当前位置:网站首页>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;
}边栏推荐
- The difference between SaaS software and traditional software delivery mode
- 数字藏品赋能实体产业释放了哪些利好?
- Management system of borrowed books based on SSM framework
- 数字藏品市场才刚刚开始
- PAT 乙等 1012 C语言
- Advanced Mathematics (Seventh Edition) Tongji University exercises 1-7 personal solutions
- 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
- Yingjixin ip6806 wireless charging scheme 5W Qi certified peripheral simplified 14 devices
- Centos7部署radius服务-freeradius-3.0.13-15.el7集成mysql
- 技术开发团队视角看到的数字藏品机遇与挑战
猜你喜欢

Wechat applet: Star Trek spaceship ticket production and generation

数字藏品火热背后需要强大的技术团队支持 北方技术团队

Wechat applet: a new interesting test

数字藏品赋能实体产业释放了哪些利好?

MySQL面试真题(二十七)——RFM分析法对用户进行分类

编址和编址单位

The construction of digital factory can be divided into three aspects

visdom画多条动态损失曲线

技能自检 | 想当测试Leader,这6项技能你会吗?

New classes are launched | 5 minutes each time, you can easily play with Alibaba cloud container service!
随机推荐
Real MySQL interview question (XXVIII) -- case - Analysis of indicators of communication operators
工作积累-判断GPS是否打开
PAT 乙等 1009 C语言
Excel sheet column title for leetcode Title Resolution
JS interview question - anti shake function
AHA C language Chapter 7 you can do more with it (talks 27-28)
visdom的使用
【数据库备份】通过定时任务完成MySQL数据库的备份
MySQL面试真题(二十六)——滴滴2020年笔试题
AHA C language Chapter 8 game time is up (lesson 29)
True question of MySQL interview (29) -- case - finding favorite movies
阿里云对象存储oss+picgo+typora实现构建图床
[proteus simulation] Arduino uno+pcf8574+lcd1602+mpx4250 electronic scale
Real MySQL interview questions (XXVI) -- didi 2020 written examination questions
如何指定pig-register项目日志的输出路径
PAT 乙等 1013 C语言
Lottery DDD code
Wireshark TS | 视频 APP 无法播放问题
What does the English letter PC mean? What does the Internet PC mean
[Stanford Jiwang cs144 project] lab2: tcpreceiver