当前位置:网站首页>PAT 乙等 1012 C语言
PAT 乙等 1012 C语言
2022-06-23 04:11:00 【章鱼bro】
1012. 数字分类 (20)
给定一系列正整数,请按要求对数字进行分类,并输出以下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
代码:
//开始时间20:49
//结束时间21:40
#include "stdio.h"
#include "stdlib.h"
int main()
{
int N;
int A1,A2,A3,A5;
A1 = A2 = A3 = A5 = 0;
int flag_2 = -1;//2的符号位
double A4;//A4要保留小数点
A4 = 0.0;
int count_1,count_2,count_3,count_4,count_5;
count_1 = count_2 = count_3 = count_4 = count_5 = 0;
scanf("%d",&N);
int * array = (int *)malloc(N * sizeof(int));
int i;
for(i = 0; i < N; i++)
{
scanf("%d",&array[i]);
}
for(i = 0; i < N; i++)
{
switch(array[i] % 5)
{
case 0:
if(array[i] % 2 == 0)
{
A1 += array[i];
count_1++;
}
break;
case 1:
flag_2 *= -1;
A2 += flag_2*array[i];
count_2++;
break;
case 2:
count_3++;
break;
case 3:
count_4++;
A4 += array[i];
break;
case 4:
if(A5 < array[i])
A5 = array[i];
count_5++;
break;
default: break;
}
}
A4 = A4 / count_4;
if(count_1 == 0)
printf("N ");
else
printf("%d ",A1);
if(count_2 == 0)
printf("N ");
else
printf("%d ",A2);
if(count_3 == 0)
printf("N ");
else
printf("%d ",count_3);
if(count_4 == 0)
printf("N ");
else
printf("%.1f ",A4);
if(count_5 == 0)
printf("N");
else
printf("%d",A5);
return 0;
}边栏推荐
- How to move the software downloaded from win11 app store to the desktop
- PAT 乙等 1022 D进制的A+B
- [graduation season u; advanced technology Er] farewell to the confused self in the past two years. Regroup, junior I'm coming
- 数字藏品赋能实体产业释放了哪些利好?
- 【数据库备份】通过定时任务完成MySQL数据库的备份
- Redis cache penetration solution - bloom filter
- MySQL面试真题(二十九)——案例-找到爱看的电影
- PAT 乙等 1026 程序运行时间
- 啊哈C语言 第8章 游戏时间到了(第29讲)
- 移动电源快充QC3.0方案芯片IP5318快充方案
猜你喜欢

华为软硬件生态圈成型,从根子上改变美国对软硬件体系的领导地位

True question of MySQL interview (29) -- case - finding favorite movies

数字藏品市场才刚刚开始

Visdom draws multiple dynamic loss curves

What if win11 cannot record audio? Solution of win11 unable to input sound

数字藏品到底有什么魔力?目前有哪些靠谱的团队在开发

What benefits have digital collections enabled the real industry to release?

数字藏品——新的投资机遇
![[image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code](/img/e2/24eb2a60e3dc603b3ec4bfefd0b8e5.png)
[image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code

How can digital collections empower economic entities?
随机推荐
华为软硬件生态圈成型,从根子上改变美国对软硬件体系的领导地位
基于SSM框架的借阅图书管理系统
Alibaba cloud object storage oss+picgo+typera implements the construction map
ssm项目搭建
Shifu, the open source development platform of the Internet of things, is open for internal testing! Release of the first version of technical documents
AI艺术的基因工程?使用 #Artbreeder 改变图像的任意形态
How to move the software downloaded from win11 app store to the desktop
Current situation and development of containerization technology under the cloud native trend
数字藏品如何赋能经济实体?
数字藏品市场才刚刚开始
Opencv display image
Redis缓存穿透解决方案-布隆过滤器
Advanced Mathematics (Seventh Edition) Tongji University exercises 1-8 personal solutions
常用的无线充发射IC芯片
Fs2119a Synchronous Boost IC output 3.3V and fs2119b Synchronous Boost IC output 5V
Jvm: when a method is overloaded, the specific method to call is determined by the static type of the incoming parameter rather than the actual type of the parameter
Wechat applet: wechat can also send flash photos to create wechat applet source code download and customize flash time
iNFTnews | 加密之家从宇宙寄来的明信片,你会收到哪一张?
ORB_SLAM2运行
Mobile power fast charging qc3.0 scheme chip ip5318 fast charging scheme