当前位置:网站首页>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;
}边栏推荐
- 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
- Visdom draws multiple dynamic loss curves
- Deploy docker and install MySQL in centos7
- The difference between SaaS software and traditional software delivery mode
- [graduation season u; advanced technology Er] farewell to the confused self in the past two years. Regroup, junior I'm coming
- PAT 乙等 1011 C语言
- Basic calculator for leetcode topic analysis
- 最优传输理论下对抗攻击可解释性
- jvm-05.垃圾回收
- MySQL面试真题(二十六)——滴滴2020年笔试题
猜你喜欢

Kotlin android简单Activity跳转、handler和thread简单配合使用

The digital collection market has just begun

Three most advanced certifications, two innovative technologies and two outstanding cases, Alibaba cloud appeared at the cloud native industry conference

MySQL面试真题(三十)——贝壳-房产订单分析

HierarchyViewer工具找不到 HierarchyViewer位置

Genetic engineering of AI art? Use # artbreeder to change any shape of the image

New classes are launched | 5 minutes each time, you can easily play with Alibaba cloud container service!

How does win11 enable mobile hotspot? How to enable mobile hotspot in win11

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

What does the English letter PC mean? What does the Internet PC mean
随机推荐
华为软硬件生态圈成型,从根子上改变美国对软硬件体系的领导地位
True MySQL interview question (XXII) -- condition screening and grouping screening after table connection
Low cost 5W wireless charger scheme fs68001b simple charging chip
Alibaba cloud object storage oss+picgo+typera implements the construction map
技术开发团队视角看到的数字藏品机遇与挑战
制造业数字化转型存在问题及原因分析
How to move the software downloaded from win11 app store to the desktop
Leetcode topic analysis add binary
Skill self check | do you know these 6 skills if you want to be a test leader?
jvm-06.垃圾回收器
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
使用链表实现两个多项式相加和相乘
Advanced Mathematics (Seventh Edition) Tongji University exercises 1-7 personal solutions
Advanced Mathematics (Seventh Edition) Tongji University exercises 1-8 personal solutions
MySQL面试真题(二十四)——行列互换
The 510000 prize pool invites you to participate in the competition -- the second Alibaba cloud ECS cloudbuild developer competition is coming
【数据库备份】通过定时任务完成MySQL数据库的备份
Dolphin scheduler dolphin scheduling upgrade code transformation -upgradedolphin scheduler
[Stanford Jiwang cs144 project] lab2: tcpreceiver
数字藏品如何赋能经济实体?