当前位置: 首页 > news >正文

【PAT甲级】1153 Decode Registration Card of PAT

【PAT题解集合】

1153 Decode Registration Card of PAT

题目详情 - 1153 Decode Registration Card of PAT (pintia.cn)

中文翻译

A registration card number of PAT consists of 4 parts:

  • the 1st letter represents the test level, namely, T for the top level, A for advance and B for basic;
  • the 2nd - 4th digits are the test site number, ranged from 101 to 999;
  • the 5th - 10th digits give the test date, in the form of yymmdd;
  • finally the 11th - 13th digits are the testee’s number, ranged from 000 to 999.

Now given a set of registration card numbers and the scores of the card owners, you are supposed to output the various statistics according to the given queries.

Input Specification:

Each input file contains one test case. For each case, the first line gives two positive integers N (≤104) and M (≤100), the numbers of cards and the queries, respectively.

Then N lines follow, each gives a card number and the owner’s score (integer in [0,100]), separated by a space.

After the info of testees, there are M lines, each gives a query in the format Type Term, where

  • Type being 1 means to output all the testees on a given level, in non-increasing order of their scores. The corresponding Term will be the letter which specifies the level;
  • Type being 2 means to output the total number of testees together with their total scores in a given site. The corresponding Term will then be the site number;
  • Type being 3 means to output the total number of testees of every site for a given test date. The corresponding Term will then be the date, given in the same format as in the registration card.

Output Specification:

For each query, first print in a line Case #: input, where # is the index of the query case, starting from 1; and input is a copy of the corresponding input query. Then output as requested:

  • for a type 1 query, the output format is the same as in input, that is, CardNumber Score. If there is a tie of the scores, output in increasing alphabetical order of their card numbers (uniqueness of the card numbers is guaranteed);
  • for a type 2 query, output in the format Nt Ns where Nt is the total number of testees and Ns is their total score;
  • for a type 3 query, output in the format Site Nt where Site is the site number and Nt is the total number of testees at Site. The output must be in non-increasing order of Nt’s, or in increasing order of site numbers if there is a tie of Nt.

If the result of a query is empty, simply print NA.

Sample Input:

8 4
B123180908127 99
B102180908003 86
A112180318002 98
T107150310127 62
A107180908108 100
T123180908010 78
B112160918035 88
A107180908021 98
1 A
2 107
3 180908
2 999

Sample Output:

Case 1: 1 A
A107180908108 100
A107180908021 98
A112180318002 98
Case 2: 2 107
3 260
Case 3: 3 180908
107 2
123 2
102 1
Case 4: 2 999
NA

思路

PAT 准考证号由 4 部分组成:

  • 1 位是级别,即 T 代表顶级;A 代表甲级;B 代表乙级;
  • 2∼4 位是考场编号,范围从 101999
  • 5∼10 位是考试日期,格式为年、月、日顺次各占 2 位;
  • 最后 11∼13 位是考生编号,范围从 000999

具体思路如下:

  1. 输入所有的准考证信息,用一个结构体数组存储,方便后续排序使用。
  2. 每个样例都先输出 Case T: t c
    1. 如果 type==1 ,需要我们按照分数降序输出,如果分数相等则按照 id 的字典序从小到大输出。
    2. 如果 type==2 ,需要输出与考场编号 c 相同的所有人的成绩总和。
    3. 如果 type==3 ,需要输出与考试日期 c 相同的考场编号以及对应人数。
  3. 注意,如果上面需要输出的信息不存在,则输出 NA 即可。

代码

#include<bits/stdc++.h>
using namespace std;

const int N = 10010;
int n, m;
struct Person
{
    string id;
    int grade;
    bool operator <(const Person& p)const
    {
        if (grade != p.grade)  return grade > p.grade;   //按照分数降序
        return id < p.id; //按照id字典序升序
    }
}p[N];

int main()
{
    cin >> n >> m;

    //输入所有准考证信息
    for (int i = 0; i < n; i++)    cin >> p[i].id >> p[i].grade;

    for (int i = 1; i <= m; i++)
    {
        string t, c;
        cin >> t >> c;
        printf("Case %d: %s %s\n", i, t.c_str(), c.c_str());

        if (t == "1")
        {
            vector<Person> persons;
            for (int i = 0; i < n; i++)    //将符合等级的加入数组中
                if (p[i].id[0] == c[0])
                    persons.push_back(p[i]);

            sort(persons.begin(), persons.end());    //排序

            if (persons.empty()) puts("NA");
            else
                for (auto x : persons)
                    printf("%s %d\n", x.id.c_str(), x.grade);
        }
        else if (t == "2")
        {
            int sum = 0, cnt = 0;
            for (int i = 0; i < n; i++)
                if (p[i].id.substr(1, 3) == c)
                    sum += p[i].grade, cnt++;

            if (!cnt)    puts("NA");
            else    printf("%d %d\n", cnt, sum);
        }
        else
        {
            //先用哈希表对考场编号进行分类
            unordered_map<string, int> hash;
            for (int i = 0; i < n; i++)
                if (p[i].id.substr(4, 6) == c)
                    hash[p[i].id.substr(1, 3)]++;

            //再用容器进行排序操作
            vector<pair<int, string>> rooms;
            for (auto x : hash)    //加负号相当于进行降序操作
                rooms.push_back({ -x.second,x.first });

            sort(rooms.begin(), rooms.end());

            if (rooms.empty())   puts("NA");
            else
                for (auto x : rooms)
                    printf("%s %d\n", x.second.c_str(), -x.first);
        }
    }

    return 0;
}

相关文章:

  • 五、JAVA基本数据类型
  • 线性代数学习笔记8-4:正定矩阵、二次型的几何意义、配方法与消元法的联系、最小二乘法与半正定矩阵A^T A
  • Postgres数据库使用any和all判断数组解决IN和NOT IN条件参数超限的问题
  • Kubernetes控制平面组件:Scheduler调度器
  • AtCoder Beginner Contest 266 ABC题解
  • AJAX(异步的 JavaScript 和 XML)
  • 线性代数学习笔记8-2:对称矩阵和Hermitian矩阵、共轭转置、正定矩阵
  • 谷粒商城 (七) --------- SpringCloud Alibaba 基础配置
  • Springboot 如何在连接池未加载前从AWS,Azure等云上获取数据库密码
  • 猿创征文|在CSDN学习的那些事
  • springboot 缓存一致性常用解决方案
  • ST推出 28nm MCU ,NXP更狠,推出16nm MCU
  • 系统检测工具
  • GCN笔记:Graph Convolution Neural Network,ChebNet
  • [JavaWeb学习] Spring Ioc和DI概念思想
  • Effective Java 笔记(一)
  • ES6 学习笔记(一)let,const和解构赋值
  • Fabric架构演变之路
  • Git 使用集
  • JS函数式编程 数组部分风格 ES6版
  • JS实现简单的MVC模式开发小游戏
  • PV统计优化设计
  • RxJS 实现摩斯密码(Morse) 【内附脑图】
  • Theano - 导数
  • 半理解系列--Promise的进化史
  • 测试如何在敏捷团队中工作?
  • 关于Android中设置闹钟的相对比较完善的解决方案
  • 聚类分析——Kmeans
  • 你真的知道 == 和 equals 的区别吗?
  • 盘点那些不知名却常用的 Git 操作
  • 十年未变!安全,谁之责?(下)
  • 怎么把视频里的音乐提取出来
  • CMake 入门1/5:基于阿里云 ECS搭建体验环境
  • 仓管云——企业云erp功能有哪些?
  • 如何通过报表单元格右键控制报表跳转到不同链接地址 ...
  • ​香农与信息论三大定律
  • #QT(智能家居界面-界面切换)
  • (51单片机)第五章-A/D和D/A工作原理-A/D
  • (C语言版)链表(三)——实现双向链表创建、删除、插入、释放内存等简单操作...
  • (day 12)JavaScript学习笔记(数组3)
  • (附源码)spring boot智能服药提醒app 毕业设计 102151
  • (论文阅读30/100)Convolutional Pose Machines
  • (论文阅读32/100)Flowing convnets for human pose estimation in videos
  • (免费领源码)Python#MySQL图书馆管理系统071718-计算机毕业设计项目选题推荐
  • (三)elasticsearch 源码之启动流程分析
  • (转)为C# Windows服务添加安装程序
  • .NET Core实战项目之CMS 第一章 入门篇-开篇及总体规划
  • .NET 设计模式初探
  • .net 桌面开发 运行一阵子就自动关闭_聊城旋转门家用价格大约是多少,全自动旋转门,期待合作...
  • .NET 自定义中间件 判断是否存在 AllowAnonymousAttribute 特性 来判断是否需要身份验证
  • .NET/C# 避免调试器不小心提前计算本应延迟计算的值
  • .NetCore 如何动态路由
  • .Net的DataSet直接与SQL2005交互
  • @require_PUTNameError: name ‘require_PUT‘ is not defined 解决方法
  • [.net 面向对象程序设计进阶] (19) 异步(Asynchronous) 使用异步创建快速响应和可伸缩性的应用程序...