标签:std ace str icon scan pre oar 最大 code
给定 N 个正整数,要求你从中得到下列三种计算结果:
输入首先在第一行给出一个正整数 N,随后一行给出 N 个正整数。所有数字都不超过 100,同行数字以空格分隔。
在一行中顺序输出 A1、A2、A3的值,其间以 1 个空格分隔。如果某个数字不存在,则对应输出NONE
。
8
5 8 7 6 9 1 3 10
9 3 6.5
8
15 18 7 6 9 1 3 10
18 3 NONE
以下是AC答案
#include<iostream> #include<cstdio> using namespace std; int main() { int n; scanf("%d",&n); int a1=0,a2=0,a3=0; double suma3=0; int a[n]; for(int i=0;i<n;i++) { scanf("%d",&a[i]); } for(int i=0;i<n;i++) { if(a[i]%3==0)//A1 { if(a1<a[i]) a1=a[i]; } else if(a[i]%3==1)//A2 { a2++; } else if(a[i]%3==2)//A3 { a3++; suma3+=a[i]; } } if(a1==0) cout<<"NONE"<<‘ ‘; else cout<<a1<<‘ ‘; if(a2==0) cout<<"NONE"<<‘ ‘; else cout<<a2<<‘ ‘; if(a3==0) cout<<"NONE"; else printf("%.1f",suma3/a3); return 0; }
标签:std ace str icon scan pre oar 最大 code
原文地址:https://www.cnblogs.com/qinmin/p/12263314.html