1153 Decode Registration Card of PAT

这道题一开始一直超时,后来看了大神的发现要用unordered_map,然后还是不行,把cout改成printf,居然过了。。。时间真的掐得紧

#include <iostream>
#include <stdlib.h>
#include <string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>

#include <unordered_map>

using namespace std;

struct stu {
    string cnum;
    int score;
};

struct site {
    int num;
    string s;
};

bool cmp1(stu x, stu y) {
    if (x.score != y.score) {
        return x.score > y.score;
    }
    else {
        return x.cnum < y.cnum;
    }
}

bool cmp2(site x, site y) {
    if (x.num != y.num) {
        return x.num > y.num;
    }

    else {
        return x.s < y.s;
    }
}

int main(){

    int m, n;
    cin >> n >> m;
    vector<stu> arr;
    for (int i = 0; i < n; i++) {
        stu s;
        cin >> s.cnum >> s.score;
        arr.push_back(s);
    }

    for (int i = 0; i < m; i++) {
        int type;
        cin >> type;
        if (type == 1) {
            char level;
            cin >> level;
            int num = 0;
            sort(arr.begin(), arr.end(), cmp1);
            cout << "Case" << ‘ ‘ << i + 1 << ": " << type << ‘ ‘ << level<<endl;
            for (int j = 0; j < arr.size(); j++) {
                if (arr[j].cnum[0] == level) {
                    printf("%s %d\n", arr[j].cnum.c_str(), arr[j].score);
                    num++;
                }
            }

            if (num == 0) {
                cout << "NA" << endl;
            }
        }

        if (type == 2) {
            string site;
            cin >> site;
            int num = 0, total = 0;
            for (int j = 0; j < arr.size(); j++) {
                if (arr[j].cnum.substr(1, 3) == site) {
                    num++;
                    total += arr[j].score;
                }
            }

            cout << "Case" << ‘ ‘ << i + 1 << ": " << type << ‘ ‘ << site<<endl;

            if (num == 0) {
                cout << "NA" << endl;
            }
            else {
                cout << num << ‘ ‘ << total << endl;
            }
        }

        if (type == 3) {
            string date;
            cin >> date;
            unordered_map<string, int> m1;
            vector<site> arr1;
            for (int j = 0; j < arr.size(); j++) {
                if (arr[j].cnum.substr(4, 6) == date) {
                    m1[arr[j].cnum.substr(1, 3)]++;
                }
            }

            for (auto it : m1) {
                site temp;
                temp.s = it.first;
                temp.num = it.second;
                arr1.push_back(temp);
            }

            sort(arr1.begin(), arr1.end(), cmp2);
            cout << "Case" << ‘ ‘ << i + 1 << ": " << type << ‘ ‘ << date << endl;

            if (arr1.size() == 0) {
                cout << "NA" << endl;
            }

            else {
                for (int j = 0; j < arr1.size(); j++) {
                    printf("%s %d\n", arr1[j].s.c_str(), arr1[j].num);
                }
            }
        }
    }

    system("pause");

};

原文地址:https://www.cnblogs.com/wsggb123/p/10206062.html

时间: 2024-07-30 15:29:27

1153 Decode Registration Card of PAT的相关文章

1153 Decode Registration Card of PAT (25 分)

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

PAT Advanced 1153 Decode Registration Card of PAT (25 分)

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

1153.Decode Registration Card of PAT(unordered_map)

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 gi

PAT A1153 Decode Registration Card of PAT [硬核模拟]

题目描述 链接 给出一组学生的准考证号和成绩,准考证号包含了等级(乙甲顶),考场号,日期,和个人编号信息,并有三种查询方式 查询一:给出考试等级,找出该等级的考生,按照成绩降序,准考证升序排序 查询二:给出考场号,统计该考场的考生数量和总得分 查询三:给出考试日期,查询改日期下所有考场的考试人数,按照人数降序,考场号升序排序 分析 查询一和查询二都是可以直接遍历做到的!!!直接遍历,不用存中间状态!!!否则用map超时 查询三用unordered_map 注意!!不需要提前把所有都提取出来,变成

PAT(甲级)2018年冬季考试

1152 Google Recruitment 思路:判断素数 #include<bits/stdc++.h> using namespace std; const int maxn = 1100; int a[maxn]; int n,k; long long getNum(int pos){ long long x = 0; for(int i=pos;i<=pos+k-1;i++){ x = x*10 + a[i]; } return x; } bool prime(long lo

A题目

1 1001 A+B Format(20) 2 1002 A+B for Polynomials(25) 3 1003 Emergency(25) 4 1004 Counting Leaves(30) 5 1005 Spell It Right(20) 6 1006 Sign In and Sign Out(25) 7 1007 Maximum Subsequence Sum(25) 8 1008 Elevator(20) 9 1009 Product of Polynomials(25) 10

【译】基于主机的卡仿真(Host-based Card Emulation)

基于主机的卡仿真(Host-based Card Emulation) 能提供NFC功能很多Android手机已经支持NFC卡模拟.在大多数情况下,该卡是由设备中的单独的芯片仿真,所谓的安全元件.由无线运营商提供了许多的SIM卡还包含一个安全元件. 安卓4.4引入卡仿真的附加方法,该方法不涉及安全元件,称为基于主机的卡模拟.这允许任何Android应用程序来模拟卡,并直接与NFC读取器.本文档介绍了如何基于主机的卡仿真( HCE )适用于Android和如何使用这种技术开发的应用程序,模拟的NF

1025. PAT Ranking (25)

题目如下: Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. No

1025. PAT Ranking

1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneous