PAT (Basic Level) Practise (中文)1012. 数字分类 (20)
2017-11-01 10:21
537 查看
1012. 数字分类 (20)
时间限制100 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
给定一系列正整数,请按要求对数字进行分类,并输出以下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
#include <cstdio> const int maxn=1005; int a[maxn]; int main(){ int n; while(scanf("%d",&n)==1){ for(int i=0;i<n;i++) scanf("%d",&a[i]); int a1=0,a2=0,a3=0,a4=0,a5=0; int flag=1,cnt=0,ok=0; for(int i=0;i<n;i++){ if(a[i]%10==0) a1+=a[i]; else if(a[i]%5==1){ ok=1; a2+=flag*a[i]; flag=-flag; } 4000 else if(a[i]%5==2) a3++; else if(a[i]%5==3){ a4+=a[i]; cnt++; } else if(a[i]%5==4){ if(a[i]>a5) a5=a[i]; } } if(a1==0) printf("N "); else printf("%d ",a1); if(!ok) printf("N "); else printf("%d ",a2); if(a3==0) printf("N "); else printf("%d ",a3); if(a4==0) printf("N "); else printf("%.1f ",(double)a4/cnt); if(a5==0) printf("N\n"); else printf("%d\n",a5); } return 0; }
相关文章推荐
- PAT (Basic Level) Practise (中文)1012. 数字分类 (20) C语言
- PAT (Basic Level) Practise (中文) 1012. 数字分类 (20)
- PAT (Basic Level) Practise (中文)1012. 数字分类 (20)
- PAT (Basic Level) Practise (中文)- 1012. 数字分类 (20)
- PAT (Basic Level) Practise (中文)1012. 数字分类 (20)
- PAT (Basic Level) Practise (中文)1012. 数字分类 (20)
- PAT (Basic Level) Practise-1012. 数字分类 (20)
- PAT乙级真题及训练集 PAT (Basic Level) Practise (中文)1012. 数字分类
- PAT Basic Level 1012. 数字分类(20)
- PAT (Basic Level) Practise (中文)1044. 火星数字(20)
- PAT (Basic Level) Practise (中文)-1019. 数字黑洞 (20)
- PAT (Basic Level) Practise:1012. 数字分类
- PAT (Basic Level) Practise (中文)1019. 数字黑洞 (20)
- PAT(basic level) 1012 数字分类(20)
- PAT (Basic Level) Practise (中文)1019. 数字黑洞 (20)
- PAT (Basic Level) Practise (中文) 1044. 火星数字(20)
- PAT (Basic Level) Practise (中文)1044. 火星数字(20) C语言
- PAT (Basic Level) Practise (中文) 1019. 数字黑洞 (20)
- PAT (Basic Level) Practise (中文) 1048. 数字加密(20)
- PAT (Basic Level) Practise (中文)1019. 数字黑洞 (20)