PTA 1012 数字分类(20 分)C语言

PTA 1012 数字分类(20 分)C语言

#include
#include

int main()
{
    int n;
    scanf("%d", &n);
    int zs[n];  //n个整数
    int a1=0;
    int a2=0;
    int a3=0;
    float a4;
    float sum=0;
    int a5=0;
    int k=2;
    int q=0;
    int c1=0,c2=0,c3=0,c4=0,c5=0;  //计数,用于判断是输入每个值还是N

    for(int j=0;jscanf("%d", &zs[j]);
        if(zs[j] % 5 == 0 && zs[j] % 2 == 0)
        {
            a1 += zs[j];
            c1++;
        }
        else if(zs[j] % 5 == 1)
        {
            a2 += pow(-1, k) * zs[j];
            k++;
            c2++;
        }
        else if(zs[j] % 5 == 2)
        {
            a3 += 1;
            c3++;
        }
        else if(zs[j] % 5 == 3)
        {
            sum += zs[j];
            q=q+1;
            c4++;
        }
        else if(zs[j] % 5 == 4)
        {
            if(zs[j] > a5)
            {
                a5 = zs[j];
                c5++;
            }
        }
    }

    a4 = sum/q;
    int pr[3] = {a1, a2, a3};
    int count[5] = {c1, c2, c3, c4, c5};

    //输出判断
    for(int q=0;q<3;q++)
    {
        if(count[q] != 0)
        {
            printf("%d ", pr[q]);
        }
        else{
            printf("N ");
        }
    }
    if(count[3] != 0)
    {
        printf("%.1f ", a4);
    }
    else{
            printf("N ");
    }
    if(count[4] != 0)
    {
        printf("%d", a5);
    }
    else{
            printf("N");
    }

}

你可能感兴趣的:(PTA 1012 数字分类(20 分)C语言)