1012 数字分类 (20 分)

给定一系列正整数,请按要求对数字进行分类,并输出以下 5 个数字:

  • A​1​​ = 能被 5 整除的数字中所有偶数的和;
  • A​2​​ = 将被 5 除后余 1 的数字按给出顺序进行交错求和,即计算 n​1​​−n​2​​+n​3​​−n​4​​⋯;
  • A​3​​ = 被 5 除后余 2 的数字的个数;
  • A​4​​ = 被 5 除后余 3 的数字的平均数,精确到小数点后 1 位;
  • A​5​​ = 被 5 除后余 4 的数字中最大数字。

输入格式:

每个输入包含 1 个测试用例。每个测试用例先给出一个不超过 1000 的正整数 N,随后给出 N 个不超过 1000 的待分类的正整数。数字间以空格分隔。

输出格式:

对给定的 N 个正整数,按题目要求计算 A​1​​~A​5​​ 并在一行中顺序输出。数字间以空格分隔,但行末不得有多余空格。

若其中某一类数字不存在,则在相应位置输出 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

注意,printf函数保留小数的时候,会自动四舍五入
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#define max 1000
#define debug 0
using namespace std; int main() {
#if debug
    freopen("in.txt", "r", stdin);
#endif     int n = 0;
    int c2 = 0;
    int A1, A2, A3, A5;
    A1 = A2 = A3 = A5 = 0;
    int c4 = 0;
    double A4=0;
    cin >> n;
    int a;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        if (a % 10 == 0)
        {
            A1 += a;
        }
        if (a % 5 == 1)
        {
            a *= pow(-1,c2);
            A2 += a;
            c2++;
        }
        if (a % 5 == 2)
        {
            A3++;
        }
        if (a % 5 == 3)
        {
            A4 += a;
            c4++;
        }
        if (a % 5 == 4)
        {
            if (A5 < a)
            {
                A5 = a;
            }
        }
    }
    if(c4!=0)
    A4 = A4/c4;
    if (A1 == 0)
        cout << 'N';
    else
        cout << A1;
    cout << ' ';
    if(c2==0)
        cout << 'N';
    else
        cout << A2;
    cout << ' ';
    if (A3 == 0)
        cout << 'N';
    else
        cout << A3;
    cout << ' ';    
    if (A4 == 0)
        cout << 'N';
    else
        printf("%.1f", A4);
    cout << ' ';
    if (A5 == 0)
        cout << 'N';
    else
        cout << A5;
#if debug
    freopen("CON", "r", stdin);
#endif
    return 0;
}

PAT Basic 1012的更多相关文章

  1. PAT Basic 1012 数字分类 (20 分)

    给定一系列正整数,请按要求对数字进行分类,并输出以下 5 个数字: A​1​​ = 能被 5 整除的数字中所有偶数的和: A​2​​ = 将被 5 除后余 1 的数字按给出顺序进行交错求和,即计算 n ...

  2. PAT甲级1012. The Best Rank

    PAT甲级1012. The Best Rank 题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同 ...

  3. PAT Basic 1057

    1057 数零壹 给定一串长度不超过 10​5​​ 的字符串,本题要求你将其中所有英文字母的序号(字母 a-z 对应序号 1-26,不分大小写)相加,得到整数 N,然后再分析一下 N 的二进制表示中有 ...

  4. PAT (Basic Level) Practise (中文)-1039. 到底买不买(20)

    PAT (Basic Level) Practise (中文)-1039. 到底买不买(20) http://www.patest.cn/contests/pat-b-practise/1039 小红 ...

  5. PAT (Basic Level) Practise (中文)- 1022. D进制的A+B (20)

    PAT (Basic Level) Practise (中文)-  1022. D进制的A+B (20)  http://www.patest.cn/contests/pat-b-practise/1 ...

  6. PAT (Basic Level) Practise (中文)- 1024. 科学计数法 (20)

    PAT (Basic Level) Practise (中文)- 1024. 科学计数法 (20) http://www.patest.cn/contests/pat-b-practise/1024 ...

  7. PAT (Basic Level) Practise (中文)-1025. 反转链表 (25)

    PAT (Basic Level) Practise (中文)-1025. 反转链表 (25)   http://www.patest.cn/contests/pat-b-practise/1025 ...

  8. PAT (Basic Level) Practise (中文)- 1026. 程序运行时间(15)

    PAT (Basic Level) Practise (中文)- 1026. 程序运行时间(15)    http://www.patest.cn/contests/pat-b-practise/10 ...

  9. PAT (Basic Level) Practise (中文)-1027. 打印沙漏(20)

    PAT (Basic Level) Practise (中文)-1027. 打印沙漏(20)  http://www.patest.cn/contests/pat-b-practise/1027 本题 ...

随机推荐

  1. Android常用框架和控件使用

    Router框架 https://github.com/iqiyi/Andromeda/blob/master/CHINESE_README.md https://github.com/alibaba ...

  2. MyBatis配置:在控制台打印SQL语句

    1.在spring-mybatis.xml中配置语句 注意:value=”classpath:mybatis-config.xml”这个文件如果之前没有,是需要新建的  2.新建mybatis-con ...

  3. Debug.Assert vs Exception Throwing(转载)

    来源 Q: I've read plenty of articles (and a couple of other similar questions that were posted on Stac ...

  4. 一个kubeadm.config文件--定义了token,扩展了默认端口,外部ETCD集群,自定义docker仓库,基于ipvs的kubeproxy

    这个版本是基于kubeadm.k8s.io/v1alpha3的,如果到了beta1,可能还要变动呢. apiVersion: kubeadm.k8s.io/v1alpha3 kind: InitCon ...

  5. Hbase启动hbase shell运行命令报Class path contains multiple SLF4J bindings.错误

    1:Hbase启动hbase shell运行命令报Class path contains multiple SLF4J bindings.错误,是因为jar包冲突了,所以对于和hadoop的jar包冲 ...

  6. es6 Proxy

    proxy在语言层面去操作一个对象 var user={}; user.fname='Bob'; user.lname="Wood"; user.fullName= functio ...

  7. jxoi2017

    题解: 并不知道题目顺序就按照难度排序了 [JXOI2017]加法 这是一道很简单的贪心 最小值最大二分答案 然后我们可以从左向右考虑每一个位置 如果他还需要+A 我们就从能覆盖它的区间中挑一个最右的 ...

  8. python--return小练习

    #返回单个值,return a:#一个return后的语句不再执行,def calc_sum(*args): ax = 0 for n in args: ax = ax + nprint(ax); r ...

  9. P1057 传球游戏 dp

    题目描述 上体育课的时候,小蛮的老师经常带着同学们一起做游戏.这次,老师带着同学们一起做传球游戏. 游戏规则是这样的:nn个同学站成一个圆圈,其中的一个同学手里拿着一个球,当老师吹哨子时开始传球,每个 ...

  10. 025 SSM简单搭建

    参考了同事的文档,自己也写一篇文档. 同时,补充了一下,程序是如何运行的. 一:SSM框架 1.说明 SSM(Spring+SpringMVC+MyBatis)框架集由Spring.SpringMVC ...