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 "stdafx.h"
#include "iostream"
int main()
{
int i=0;
scanf("%d",&i);
int a[10000]={0};
int count[5]={0};
for(int n=0;n<i;n++){
scanf("%d",&a[n]);
}
int sum_odd=0;
int sum_divide=0;
int num=0;//余2个数
int sum_three=0;//余三数的和
int num_three=0;//余三数的个数
int max_four=0;
bool flag=true;//记录交错顺序
for(int n=0;n<i;n++){
if(a[n]%5==0)
{
if(a[n]%2==0)
{
count[0]++;
sum_odd+=a[n];
continue;
}
}
if(a[n]%5==1)
{
if(flag)
{
sum_divide+=a[n];
flag=false;
}
else
{
sum_divide-=a[n];
flag=true;
}
count[1]++;
continue;
}
if(a[n]%5==2)
{
num++;
count[2]++;
continue;
}
if(a[n]%5==3){
sum_three+=a[n];
num_three++;
count[3]++;
continue;
}
if(a[n]%5==4){
count[4]++;
if(a[n]>max_four)
max_four=a[n];
continue;
}
}
if(count[0]==0) printf("N ");
else printf("%d ",sum_odd);
if(count[1]==0) printf("N ");
else printf("%d ",sum_divide);
if(count[2]==0) printf("N ");
else printf("%d ",num);
if(count[3]==0) printf("N ");
else printf("%.1f ",(double)sum_three/num_three);
if(count[4]==0) printf("N");
else printf("%d",max_four);
}
查看提交
评测结果
时间 | 结果 | 得分 | 题目 | 语言 | 用时(ms) | 内存(kB) | 用户 |
---|---|---|---|---|---|---|---|
10月18日 10:15 | 答案正确 | 20 | 1012 | C++ (g++ 4.7.2) | 0 | 436 | 鸭鸭 |
测试点
测试点 | 结果 | 用时(ms) | 内存(kB) | 得分/满分 |
---|---|---|---|---|
0 | 答案正确 | 0 | 272 | 8/8 |
1 | 答案正确 | 0 | 256 | 5/5 |
2 | 答案正确 | 0 | 432 | 1/1 |
3 | 答案正确 | 0 | 384 | 1/1 |
4 | 答案正确 | 0 | 316 | 1/1 |
5 | 答案正确 | 0 | 312 | 1/1 |
6 | 答案正确 | 0 | 268 | 1/1 |
7 | 答案正确 | 0 | 316 | 1/1 |
8 | 答案正确 | 0 | 436 | 1/1 |