1012. 数字分类 (20)
来源:互联网 发布:网络销售授权书模板 编辑:程序博客网 时间:2024/06/09 17:16
给定一系列正整数,请按要求对数字进行分类,并输出以下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
CODE:
#include<iostream>#include<cmath>#include <iomanip>using namespace std;int main(){ int n,x,flag=0,count=0; int a1=0,a2=0,a3=0,a5=0; int e1=0,e2=0,e3=0,e4=0,e5=0; float a4=0; cin>>n; for(int i=0;i<n;i++){ cin>>x; switch(x%5){ case 0://x%10==0 if(x%2==0){ a1+=x; e1=1; }break; case 1:a2+=pow(-1,flag)*x;flag++;e2=1;break; case 2:a3++;e3=1;break; case 3:a4+=x;count++;e4=1;break; case 4:if(x>a5){ a5=x; e5=1; }break; } } if(!e1){ cout<<"N"<<" "; }else{ cout<<a1<<" "; } if(!e2){ cout<<"N"<<" "; }else{ cout<<a2<<" "; } if(!e3){ cout<<"N"<<" "; }else{ cout<<a3<<" "; } if(!e4){ cout<<"N"<<" "; }else{ cout<<setiosflags(ios::fixed)<<setprecision(1)<<a4/count<<" "; //printf("%0.1f",a4); } if(!e5){ cout<<"N"; }else{ cout<<a5; } return 0;}
0 0
- 1012. 数字分类 (20)
- 1012. 数字分类 (20)
- 1012. 数字分类 (20)
- 1012. 数字分类 (20)
- 1012. 数字分类 (20)
- 1012. 数字分类 (20)
- 1012. 数字分类 (20)
- 1012. 数字分类 (20)
- 1012. 数字分类 (20)
- 1012. 数字分类 (20)
- 1012. 数字分类 (20)
- 1012. 数字分类 (20)
- 1012. 数字分类 (20)
- 1012. 数字分类 (20)
- 1012. 数字分类 (20)
- 1012. 数字分类 (20)
- 1012. 数字分类 (20)
- 1012. 数字分类 (20)
- collection view 自定义
- RingtoneManager
- Python:文件操作
- iOS友盟推送
- 第5周项目1(3)三角形类雏形
- 1012. 数字分类 (20)
- JDK中的URLConnection参数详解
- error C2065: 'Public_Area' : undeclared identifier
- 第5周项目4—长方柱类
- jQuery选择器案例
- java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before
- 模版元编程之——Type Traits
- Qt提取EXE文件的大图标
- 笔试and心态