P5718 【深基4.例2】找最小值

#include<stdio.h>
int main()
{
    int a[101], n,min=0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    min = a[0];
    for (int i=0; i < n; i++)
    {
        if (a[i] < min)
            min = a[i];
    }
    printf("%d", min);
    return 0;
}

P5719 【深基4.例3】分类平均

#include<stdio.h>
int main()
{
    int n, k,kcon=0;
    double aarr, barr,sn=0,sk=0;
    scanf("%d%d", &n,&k);
    for (int i = 1; i <= n; i++)
    {
        if (i % k == 0)
        {
            sk += i;
            kcon++;
        }
        sn += i;
    }
    barr = (sn - sk) / (n - kcon);
    aarr = sk / kcon;
    printf("%.1f %.1f",aarr ,barr);
    return 0;
}

P5720 【深基4.例4】一尺之棰

#include<stdio.h>
int main()
{
    int a,out=0;
    scanf("%d", &a);
    while (a>=1)
    {
        out++;
        a = a / 2;
    }
    printf("%d", out);
    return 0;
}

P5721 【深基4.例6】数字直角三角形

#include<stdio.h>
int main()
{
    int a, i, j, out = 0;//i行,j列
    scanf("%d", &a);
    for (i = 1; i <= a; i++)
    {
        for (j = a; j >= i; j--)
        {
            out++;
            if (out < 10)
                printf("0%d", out);
            else
                printf("%d", out);
        }
        printf("\n");
    }
    return 0;
}

P1009 阶乘之和

注,因范围原因,并未通过全部测试点,练题考试用,故只写到这里不考虑高精度
#include<stdio.h>
int main()
{
    long int n,s=0,t=1;
    scanf("%ld", &n);
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= i; j++)
        {
            t *= j;
        }
        s += t;
        t = 1;
    }
    printf("%ld", s);
    return 0;
}


P1980 计数问题

#include "stdio.h"
int main()
{
    int n, x, out = 0;
    scanf("%d%d", &n, &x);
    for (int i = 1; i <= n; i++)
    {
        int tmp , tmp1;
        tmp = i;
        while (tmp > 0)
        {
            tmp1 = tmp % 10;
            tmp = tmp / 10;
            if (tmp1 == x)
                out++;
        }
    }
    printf("%d", out);
    return 0;
}

P1035 级数求和

#include "stdio.h"
int main()
{
    int k,n=1;
    double s=0.0;
    scanf("%d", &k);
    while (s<=k)
    {
        s += 1.0 / n;
        n++;
    }
    printf("%d", n-1);
    return 0;
}

P2669 金币

#include<stdio.h>
int main() 
{
    int a, s = 0, i, j, count = 0,flog=0;
    scanf("%d", &a);
    for (i = 1; i <= a; i++) {
        for (j = 1; j <= i; j++) {
            s = i + s;
            count++;
            if (count >= a)
            {
                flog = 1;
                break;    
            }
        }
        if (flog == 1)
            break;

    }
    printf("%d", s);
    return 0;
}

P5722 【深基4.例11】数列求和

#include<stdio.h>
int main()
{
    int n,s=0;
    scanf("%d", &n);
    while (n != 0)
    {
        s += n--;
    }
    printf("%d", s);
    return 0;
}

P5723 【深基4.例13】质数口袋

#include<stdio.h>
int prime(int a) 
{
    int i, flog = 1;
    for (i = 2; i < a; i++) {
        if (a % i == 0) 
        {
            flog = 0;
            break;
        }
    }
    return flog;
}

int main() 
{
    int  a, i, b, c = 0, count = 0;
    scanf("%d", &a);
    for (i = 2; i <= a; i++) 
    {
        b = prime(i);
        if (b == 1) 
        {
            if (c + i > a) break;
            printf("%d\n", i);
            c = c + i;
            count++;
        }
    }
    printf("%d", count);
    return 0;
}

[P1217 [USACO1.5]回文质数 Prime Palindromes](https://www.luogu.com.cn/problem/P1217)

P1423 小玉在游泳

#include <stdio.h>
int main()
{
    float a=0,s=0,tmp=2;
    int i=0;
    scanf("%f", &a);
    while (s <= a)
    {
        s = tmp + s;
        tmp = tmp * 0.98;
        i++;
    }
    printf("%d", i);
    return 0;
}

P1307 数字反转

#include<stdio.h>
int main()
{
    int a,i,sum=0,b,c;
    scanf("%d",&a);
    c=a;
    if(a<0) a=-a;
    while(a)
    {
        b=a%10;
        sum=sum*10+b;
        a=a/10;
    }
    if(c<0)
    {
        sum=-sum;    
    }        
    printf("%d",sum);
    return 0;
}

P1720 月落乌啼算钱

#include <stdio.h>
#include <math.h>
int main()
{
    int n;
    double fn,fz1=1,fz2=1;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        fz1 *= (1 + sqrt(5)) / 2;
        fz2 *= (1 - sqrt(5)) / 2;
    }
    fn = (fz1 - fz2) / sqrt(5);
    printf("%.2f", fn);
    return 0;
}

P5724 【深基4.习5】求极差

#include<stdio.h>
int main(){
    int a[1000],b,i,j,t,c;
    scanf("%d",&b);
    for(i=0;i<b;i++)
    scanf("%d",&a[i]);
    for(i=0;i<b-1;i++){
        for(j=0;j<b-1-i;j++){
            if(a[j]>a[j+1]){
                t=a[j];
                a[j]=a[j+1];
                a[j+1]=t;
            }
        }
    }
    c=a[b-1]-a[0];
    printf("%d",c);
    return 0;
}

P1420 最长连号

#include <stdio.h>
#include <math.h>
int main()
{
    int n, a[10000], cont = 1, out = 1;;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    for (int i = 0; i < n; i++)
    {
        if (a[i] + 1 == a[i + 1])
        {
            cont++;
        }
        else cont = 1;
        if (cont > out)
        {
            out = cont;
        }
    }
    printf("%d", out);
    return 0;
}

P1075 质因数分解

#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 2; i <= n; i++)
        if (n % i == 0)
        {
            printf("%d", n / i);
            return 0;
        }
}

P5725 【深基4.习8】求三角形

#include<stdio.h>
int main()
{
    int a, i, j, out = 0;//i行,j列
    scanf("%d", &a);
    for (i = 1; i <= a; i++)
    {
        for (j = 1; j <= a; j++)
        {
            out++;
            if (out < 10)
                printf("0%d", out);
            else
                printf("%d", out);
        }
        printf("\n");
    }
    printf("\n");
    out = 0;
    for (i = 1; i <= a; i++)
    {
        for (j = a; j > i; j--)
        {
            printf("  ");

        }
        for (j = 0; j < i; j++)
        {
            out++;
            if (out < 10)
                printf("0%d", out);
            else
                printf("%d", out);
        }
        printf("\n");
    }
    return 0;
}

P5726 【深基4.习9】打分

#include <stdio.h>
int main()
{
    int a[1001],n,t;
    float s=0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = 0; j < n - i - 1; j++)
        {
            if (a[j] > a[j + 1])
            {
                t = a[j];
                a[j] = a[j + 1];
                a[j + 1] = t;
            }
        }
    }
    for (int i = 1; i < n - 1; i++)
    {
        s = s + a[i];
    }
    printf("%.2f", s / (n - 2));
    return 0;
}

[P4956 [COCI2017-2018#6] Davor](https://www.luogu.com.cn/problem/P4956)

P1089 津津的储蓄计划

#include "stdio.h"
int main()
{
    int hua, ziji = 0, h = 0;
    for (int i = 1; i <= 12; i++)
    {
        scanf("%d", &hua);
        ziji = ziji + 300 - hua;
        if (ziji < 0)
        {
            printf("-%d", i);
            return 0;
        }
        else
        {
            h = ziji / 100 + h;
            ziji = ziji % 100;
        }
    }
    printf("%d", 120 * h + ziji);
    return 0;
}
最后修改:2020 年 04 月 16 日 10 : 23 PM