当前位置:网站首页>Pat class B 1012 C language
Pat class B 1012 C language
2022-06-23 05:54:00 【Octopus bro】
1012. Digital classification (20)
Given a series of positive integers , Please classify the numbers as required , And output the following 5 A digital :
- A1 = Can be 5 The sum of all even numbers in a divisible number ;
- A2 = Will be 5 Except after 1 The numbers of are interleaved and summed in the given order , Computation n1-n2+n3-n4...;
- A3 = By 5 Except after 2 Number of digits of ;
- A4 = By 5 Except after 3 The average number of , Accurate to the decimal point 1 position ;
- A5 = By 5 Except after 4 The largest number of .
Input format :
Each input contains 1 Test cases . Each test case shall be provided with no more than one 1000 The positive integer N, Subsequently given N No more than one. 1000 Of positive integers to be classified . Numbers are separated by spaces .
Output format :
For given N A positive integer , Calculated according to the requirements of the title A1~A5 And output in order in one line . Numbers are separated by spaces , But there must be no extra space at the end of the line .
If one of the numbers does not exist , Output at corresponding position “N”.
sample input 1:13 1 2 3 4 5 6 7 8 9 10 20 16 18
sample output 1:30 11 2 9.7 9
sample input 2:8 1 2 4 5 6 7 9 16
sample output 2:N 11 2 N 9
Code :
// Starting time 20:49
// End time 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 The sign bit of
double A4;//A4 To keep the decimal point
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;
}边栏推荐
- MySQL面试真题(二十九)——案例-找到爱看的电影
- 新课上线 | 每次 5 分钟,轻松玩转阿里云容器服务!
- jvm-02.有序性保证
- [image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code
- [OWT] OWT client native P2P E2E test vs2017 build 6: modify script automatic generation vs Project
- PAT 乙等 1018 C语言
- ORB_SLAM2运行
- android Handler内存泄露 kotlin内存泄露处理
- Yingjixin launched 4 series of lithium batteries 100W mobile power supply voltage rise and fall scheme SOC chip ip5389
- C prime plus notes d'apprentissage - 2, constantes et formatage io (I / o)
猜你喜欢

Prometheus, incluxdb2.2 installation and flume_ Export download compile use

Wireshark TS | 视频 APP 无法播放问题

Software design and Development Notes 2: serial port debugging tool based on QT design

技术开发团队视角看到的数字藏品机遇与挑战

Analysis on the problems and causes of digital transformation of manufacturing industry

MySQL面试真题(二十三)——拼多多-球赛分析

如何指定pig-register项目日志的输出路径

三项最高级认证,两项创新技术、两大优秀案例,阿里云亮相云原生产业大会

【斯坦福计网CS144项目】Lab2: TCPReceiver

jvm-04.对象的内存布局
随机推荐
Arctime makes Chinese and English subtitle video
MySQL面试真题(二十七)——RFM分析法对用户进行分类
What is the reason for the black screen of the computer monitor when the computer is turned on? What should I do about the black screen of the computer monitor
The difference between SaaS software and traditional software delivery mode
node中操作mongoDB
Digital collections - new investment opportunities
PAT 乙等 1020.月饼
Basic calculator II for leetcode topic analysis
jvm-01.指令重排
Oracle exception
[Stanford Jiwang cs144 project] lab2: tcpreceiver
Wechat applet; AI intelligent dubbing assistant
[image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code
The official artifact of station B has cracked itself!
如何指定pig-register项目日志的输出路径
PAT 乙等 1017 C语言
MySQL面试真题(二十八)——案例-通讯运营商指标分析
Heimdall database proxy scale out 20 times
AHA C language Chapter 8 game time is up (lesson 29)
数字藏品到底有什么魔力?目前有哪些靠谱的团队在开发