1012. 数字分类 (20)
时间限制
50 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
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<string> #include<algorithm> #define MAXSIZE 100005 #define Max 30 using namespace std; void A1(int *a,int N); void A2(int *a,int N); void A3(int *a,int N); void A4(int *a,int N); void A5(int *a,int N); int main() { int a[10000]; int N; cin>>N; for(int i=0;i<N;i++)cin>>a[i]; A1(a,N);cout<<" "; A2(a,N);cout<<" "; A3(a,N);cout<<" "; A4(a,N);cout<<" "; A5(a,N);cout<<endl; return 0; } void A1(int *a,int N) { int i; int sum=0; for(i=0;i<N;i++) { if(a[i]%10==0)sum+=a[i]; } if(sum==0)cout<<"N"; else cout<<sum; } void A2(int *a,int N) { int i; int sum=0; int k=0; for(i=0;i<N;i++) { if(a[i]%5==1) { k++; if(k%2==1)sum+=a[i]; else sum+=((-1)*a[i]); } } if(k==0)cout<<"N"; else cout<<sum; } void A3(int *a,int N) { int i; int k=0; for(i=0;i<N;i++) { if(a[i]%5==2) k++; } if(k==0)cout<<"N"; else cout<<k; } void A4(int *a,int N) { int i; double sum=0; int k=0; for(i=0;i<N;i++) { if(a[i]%5==3){ k++; sum+=a[i]; } } if(sum==0)cout<<"N"; else printf("%.1lf",sum/k); } void A5(int *a,int N) { int i; int max=-9999; for(i=0;i<N;i++) { if(a[i]%5==4) { if(max<a[i])max=a[i]; } } if(max==-9999)cout<<"N"; else cout<<max; }