首页
学习
活动
专区
圈层
工具
发布
29 篇文章
1
PAT (Basic Level) Practice (中文)1047 编程团体赛
2
PAT (Basic Level) Practice (中文)1083 是否存在相等的差
3
PAT (Basic Level) Practice (中文)1082 射击比赛
4
PAT (Basic Level) Practice (中文)1081 检查密码
5
PAT (Basic Level) Practice (中文)1077 互评成绩计算
6
PAT (Basic Level) Practice (中文)1076 Wifi密码
7
PAT (Basic Level) Practice (中文)1064 朋友数
8
PAT (Basic Level) Practice (中文)1063 计算谱半径
9
PAT (Basic Level) Practice (中文)1057 数零壹
10
PAT (Basic Level) Practice (中文)1056 组合数的和
11
PAT (Basic Level) Practice (中文)1042 字符统计
12
PAT (Basic Level) Practice (中文)1041 考试座位号
13
PAT (Basic Level) Practice (中文)1023 组个最小数
14
PAT (Basic Level) Practice (中文)1022 D进制的A+B
15
PAT (Basic Level) Practice (中文)1019 数字黑洞
16
PAT (Basic Level) Practice (中文)1007 素数对猜想
17
PAT (Basic Level) Practice (中文)1091 N-自守数
18
PAT (Basic Level) Practice (中文)1026 程序运行时间
19
PAT (Basic Level) Practice (中文)1061 判断题
20
PAT (Basic Level) Practice (中文)1086 就不告诉你
21
PAT (Basic Level) Practice (中文)1016 部分A+B
22
PAT (Basic Level) Practice (中文)1012 数字分类
23
PAT (Basic Level) Practice (中文)1013 数素数
24
PAT (Basic Level) Practice (中文)1011 A+B 和 C
25
PAT (Basic Level) Practice (中文)1009 说反话
26
PAT (Basic Level) Practice (中文)1008 数组元素循环右移问题
27
PAT (Basic Level) Practice (中文)1006 换个格式输出整数
28
PAT (Basic Level) Practice (中文)1004 成绩排名
29
PAT (Basic Level) Practice (中文)1002 写出这个数

PAT (Basic Level) Practice (中文)1012 数字分类

1012 数字分类

给定一系列正整数,请按要求对数字进行分类,并输出以下 5 个数字:

A1= 能被 5 整除的数字中所有偶数的和; A2= 将被 5 除后余 1 的数字按给出顺序进行交错求和,即计算 n1−n2+n3−n4⋯; A3= 被 5 除后余 2 的数字的个数; A4= 被 5 除后余 3 的数字的平均数,精确到小数点后 1 位; A5= 被 5 除后余 4 的数字中最大数字。

输入格式:

每个输入包含 1 个测试用例。每个测试用例先给出一个不超过 1000 的正整数 N,随后给出 N 个不超过 1000 的待分类的正整数。数字间以空格分隔。

输出格式:

对给定的 N 个正整数,按题目要求计算 A1–A5并在一行中顺序输出。数字间以空格分隔,但行末不得有多余空格。

若其中某一类数字不存在,则在相应位置输出 N。

输入样例 1:

13 1 2 3 4 5 6 7 8 9 10 20 16 18

输出样例 1:

30 11 2 9.7 9

输入样例 2:

8 1 2 4 5 6 7 9 16

输出样例 2:

N 11 2 N 9

代码:

代码语言:javascript
复制
#include<stdio.h>
int main()
{

        int N;
        int arr[1000001];
        scanf("%d",&N);
        int i;
        for(i=0;i<N;i++)
        {
            scanf("%d",&arr[i]);
        }
        int A1,A2,A3,A4,A5;
        int arr5[1000001];
        int t4=0;
        int temp1,temp2,temp3,temp4,temp5;
        temp1=temp2=temp3=temp4=temp5=-1;
        A1=0;
        A2=0;
        A3=0;
        A4=0;
        A5=0;
        int l=1;
        for(i=0;i<N;i++)
        {
            if(arr[i]%5==0&&arr[i]%2==0) {temp1=1;A1+=arr[i];}
            if(arr[i]%5==1){temp2=1;A2+=(arr[i]*l);l=-l;}
            if(arr[i]%5==2) {temp3=1; A3++;}
            if(arr[i]%5==3) {temp4=1; A4+=arr[i];t4++;}
            if(arr[i]%5==4) {temp5=1; arr5[A5++]=arr[i];}
        }
        //printf("a4==%d t4==%lf\n",A4,t4);
        if(temp1==1) printf("%d ",A1);
        else printf("N ");
        if(temp2==1) printf("%d ",A2);
        else printf("N ");
        if(temp3==1) printf("%d ",A3);
        else printf("N ");
        if(temp4==1) printf("%.1lf ",A4/(double)t4);
        else printf("N ");
        if(temp5==1)
        {
            int index=0;
            for(i=1;i<A5;i++)
            {
                if(arr5[i]>=arr[index]) index=i;
            }
            printf("%d\n",arr5[index]);
        }
        else printf("N\n");
        return 0;

}
下一篇
举报
领券