PAT (Basic Level)1012. 数字分类
来源:互联网 发布:百视通网络电视要密码 编辑:程序博客网 时间:2024/06/16 07:08
http://www.patest.cn/contests/pat-b-practise/1012
描述:
给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字:
输入格式:
每个输入包含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原来越觉得PAT乙级是考细心和基本功了。
#include <iostream>#include <string>#include <algorithm> #include <cmath>#include <iomanip>using namespace std;int main(){int A1=0, A2=0, A3=0, A5=0;int n4=0;double A4=0;bool f1=0, f2=0, f3=0, f4=0, f5=0;int N=0;cin >> N;int num=0;int canshu=1;for (int i = 0 ; i<N ; i++){cin >> num;switch(num%5){case 0:if(num%2==0) {f1=1;A1+=num;}break;case 1:f2=1;A2+=canshu*num;canshu *= -1;break;case 2:f3=1;A3++;break;case 3:f4=1;n4++;A4+=num;break;case 4:f5=1;if (num>A5) A5=num;break;}}if (f1==0) cout <<'N';else cout << A1;if (f2==0) cout <<' '<<'N';else cout <<' '<< A2;if (f3==0) cout <<' '<<'N';else cout <<' '<< A3;if (f4==0) cout <<' '<<'N';else cout <<setiosflags(ios::fixed) <<setprecision(1) <<' '<< A4/n4;if (f5==0) cout <<' '<<'N';else cout <<' '<< A5;return 0;}
0 0
- PAT (Basic Level)1012. 数字分类
- PAT BASIC LEVEL 1012. 数字分类 (20)
- PAT.Basic Level.T.1012.数字分类
- 【C++】浙大PAT (Basic Level)1012. 数字分类 (20)
- PAT Basic Level 1012. 数字分类(20)
- PAT (Basic Level) Practise (中文)1012. 数字分类 (20)
- PAT (Basic Level) Practise-1012. 数字分类 (20)
- PAT (Basic Level) Practise (中文)1012. 数字分类 (20)
- PAT (Basic Level) Practise (中文) 1012. 数字分类 (20)
- PAT (Basic Level) Practise (中文)1012. 数字分类 (20)
- 【PAT 乙级(Basic Level)】数字分类
- PAT(Basic Level):数字分类(20)
- PAT(Basic Level)_1012_数字分类
- Pat(Basic Level)Practice--1012(数字分类)
- Basic Level 1012. 数字分类 (20)
- PAT (Basic Level) Practise (中文)1012. 数字分类 (20) C语言
- PAT basic 1012 :数字分类
- 【PAT 乙级(Basic Level)】数字黑洞
- curl operate elasticsearch
- Ceph Calamari软件包介绍
- CSMA/CD协议
- /bin/bash^M: 坏的解释器: 没有那个文件或目录
- RTC实时时钟驱动
- PAT (Basic Level)1012. 数字分类
- 【MinaFile】【十】【2.0】自定义异常
- HTML5会让iOS和安卓开发者转行吗?
- hdu 5207 Greatest Greatest Common Divisor【筛法】【思维】
- 【IOS】分隔视图控制器 (UISplitViewController)
- 初始化mysql 用户的密码
- android prop文件解析过程
- iOS开发 ☞ Masonary适配详解
- 日期处理类 org.apache.commons.lang3.time.DateUtils