PAT Basic Level 1095 解码PAT准考证 (25 分)

题目链接:

https://pintia.cn/problem-sets/994805260223102976/problems/1071786104348536832

我的15分代码:

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

const int maxn=10010;
struct person{
    string number;
    int score;
}per[maxn],Rank_per[maxn];

unordered_map pers;
struct TEMP{
    int kaochange,renshu;
}tmp[maxn];

bool cmp(struct person a,struct person b){
    if(a.score!=b.score)    return a.score>b.score;
    else    return a.numberb.renshu;
    else    return a.kaochange>per[i].number;
        scanf("%d",&per[i].score);
        getchar();
    }
//    for(int i=0;i::iterator it=pers.begin();it!=pers.end();it++){
                tmp[w].kaochange=it->first;
                tmp[w].renshu=it->second;
                w++;
            }
            sort(tmp,tmp+w,cmp_);
            printf("Case %d: %d %06d\n",cishu,number,date);//测试点4,注意%06d格式
            if(w){
                for(int l=0;l

AC代码:

#include 
#include 
#include 
#include 
#include 
using namespace std;
struct node {
	string t;
	int value;
};

bool cmp(const node &a, const node &b) {
	return a.value != b.value ? a.value > b.value : a.t < b.t;
}
int main() {
    int n, k, num;
    string s;
    cin >> n >> k;
    vector v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i].t >> v[i].value;
    for (int i = 1; i <= k; i++) {
        cin >> num >> s;
        printf("Case %d: %d %s\n", i, num, s.c_str());
	vector ans;
	int cnt = 0, sum = 0;
	if (num == 1) {
            for (int j = 0; j < n; j++)
		if (v[j].t[0] == s[0]) ans.push_back(v[j]);
	}
	else if (num == 2) {
	    for (int j = 0; j < n; j++) {
		if (v[j].t.substr(1, 3) == s) {
			cnt++;
			sum += v[j].value;
		}

	    }
            if (cnt != 0) printf("%d %d\n", cnt, sum);
        }
	else if (num == 3) {
	    unordered_map m;
	    for (int j = 0; j < n; j++)
		if (v[j].t.substr(4, 6) == s) m[v[j].t.substr(1, 3)]++;
	    for (auto it : m) ans.push_back({ it.first, it.second });
	}
	sort(ans.begin(), ans.end(), cmp);
	for (int j = 0; j < ans.size(); j++) printf("%s %d\n", ans[j].t.c_str(), ans[j].value);
	if (((num == 1 || num == 3) && ans.size() == 0) || (num == 2 && cnt == 0)) printf("NA\n");
    }
    return 0;
}

 

你可能感兴趣的:(PAT,PAT,Basic,Level)