1153 Decode Registration Card of PAT (25分) PAT

工作量大而已。

#include<cstdio>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>

#define maxn 1010

using namespace std;

struct cardType {
    string card, date;
    char level;
    int site, score;
};

struct site {
    int num;
    int nt;
};

bool compare1(cardType a, cardType b) {
    if (a.score > b.score) return true;
    else if (a.score < b.score) return false;
    else if (a.card < b.card) return true;
    return false;
}

bool compare2(site a, site b) {
    if (a.nt > b.nt) return true;
    else if (a.nt < b.nt) return false;
    else return a.num < b.num;

}

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    cardType cardtemp;
    vector<cardType> card;
    string input;
    for (int i = 0; i < N; i++) {
        cin >> input >> cardtemp.score;
        cardtemp.card = input;
        cardtemp.level = input[0];
        string s = input.substr(1, 3);
        sscanf(s.c_str(), "%d", &cardtemp.site);
        s = input.substr(4, 6);
        cardtemp.date = s;
        card.push_back(cardtemp);
    }
    for (int i = 1; i <= M; i++) {
        int t;  // test type
        string str;
        cin >> t >> str;

        if (t == 1) {
            char testlevel = str[0];
            sort(card.begin(), card.end(), compare1);
            printf("Case %d: ", i);
            printf("%d %c\n", t, testlevel);
            bool output = false;
            for (int j = 0; j < N; j++) {
                if (card[j].level == testlevel) {
                    printf("%s %d\n", card[j].card.c_str(), card[j].score);
                    output = true;
                }
            }
            if (output == false) printf("NA\n");
        }
        else if (t == 2) {
            int nt = 0, ns = 0;
            int testsite;
            sscanf(str.c_str(), "%d", &testsite);
            for (int j = 0; j < N; j++) {
                if (card[j].site == testsite) {
                    nt++;
                    ns += card[j].score;
                }
            }
            printf("Case %d: ", i);
            if (nt == 0) printf("%d %d\nNA\n", t, testsite);
            else printf("%d %d\n%d %d\n", t, testsite, nt, ns);
        }
        else if (t == 3) {
            vector<int> ct[1000];  // count testees
            string testdate = str;
            printf("Case %d: ", i);
            cout << t << " " << testdate << endl;
            for (int j = 0; j < N; j++) {
                if (card[j].date == testdate) {
                    ct[card[j].site].push_back(j);
                }
            }
            vector<site> siterecord;
            site sitetemp;
            for (int j = 0; j < 1000; j++) {
                if (ct[j].size() != 0) {
                    sitetemp.num = j;
                    sitetemp.nt = ct[j].size();
                    siterecord.push_back(sitetemp);
                }
            }
            sort(siterecord.begin(), siterecord.end(), compare2);
            for (int j = 0; j < siterecord.size(); j++) {
                printf("%d %d\n", siterecord[j].num, siterecord[j].nt);
            }
            if (siterecord.size() == 0) printf("NA\n");
        }
    }

    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值