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. Oracle数据重复,只取一条

    --方法一 select * from tb_supply where rowid=any(select max(rowid) from tb_supply group by phone_id) -- ...

  2. WPF 下两种图片合成或加水印的方式(转载)

    来源:http://www.cnblogs.com/lxblog/ 最近项目中应用多次应用了图片合成,为了今后方便特此记下. 在WPF下有两种图片合成的方式,一种还是用原来C#提供的GDI+方式,命名 ...

  3. 解决redis aof文件过大的问题

    执行BGREWRITEAOF命令对redis的AOF进行重写 redis-cli BGREWRITEAOF 相关解释: Redis的AOF机制有点类似于Mysql binlog,是Redis的提供的一 ...

  4. [转] node.js下mongoose简单操作实例

    Mongoose API : http://mongoosejs.com/docs/api.html // mongoose 链接 var mongoose = require('mongoose') ...

  5. 详解 Java 中的三种代理模式

    代理模式 代理(Proxy)是一种设计模式,提供了对目标对象另外的访问方式;即通过代理对象访问目标对象.这样做的好处是:可以在目标对象实现的基础上,增强额外的功能操作,即扩展目标对象的功能. 这里使用 ...

  6. 查询Linux系统中glibc的版本

    编写一个简单的程序 #include <stdio.h> int main() { printf("Hello world\n"); ; } 编译 gcc test.c ...

  7. 3.ELK 之elasticsearch CRUD

    名词介绍 index: type: document: 数据类型: 索引(index)创建示例 .   type的创建(7.x之后)将会去掉该内容,点我看为什么? 参考脚本: mapping使用 其他 ...

  8. nginx的with-http_sub_module模块使用之替换字符串

    一.介绍 该ngx_http_sub_module模块是一个过滤器,通过将一个指定的字符串替换为另一个字符串来修改响应.该模块不是默认生成的,它应该使用--with-http_sub_module 配 ...

  9. Zk 集群概念

    https://blog.csdn.net/gs80140/article/details/51496925

  10. Linux LVM动态扩容

    引用自:  https://blog.csdn.net/u012439646/article/details/73380197   xfs_growfs /dev/centos/root  一.首先安 ...