PAT乙级1095 解码PAT准考证 (25 分)

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

借鉴的柳神思路
https://blog.youkuaiyun.com/liuchuo/article/details/84972869

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_map>
using namespace std;
struct node{
	string s;
	int v;
};
vector<node> stu(10000);
bool cmp(node a, node b){
	if(a.v == b.v)	return a.s < b.s;
	else	return a.v > b.v;
}
int main(){
	int N, M;
	scanf("%d%d", &N, &M);
	for(int i = 0; i < N; i++)
		cin >> stu[i].s >> stu[i].v;
	for(int i = 1; i <= M; i++){
		vector<node> result;
		int style, count = 0, score = 0;;
		string order;
		cin >> style >> order;
		printf("Case %d: %d %s\n", i, style, order.c_str());
		if(style == 1){
			for(int j = 0; j < N; j++){
				if(stu[j].s[0] == order[0])
					result.push_back(stu[j]);
			}
		}else if(style == 2){
			for(int j = 0; j < N; j++){
				if(stu[j].s.substr(1,3) == order){
					count++;
					score += stu[j].v;	
				}
			}
			if(count)	printf("%d %d\n", count, score);
		}else if(style == 3){
			unordered_map<string, int> m;
			for(int j = 0; j < N; j++)
				if(stu[j].s.substr(4, 6) == order) m[stu[j].s.substr(1, 3)]++;
			for(auto i : m)	result.push_back({i.first, i.second});	
		}
		sort(result.begin(), result.end(), cmp);
		for (int j = 0; j < result.size(); j++) printf("%s %d\n", result[j].s.c_str(), result[j].v);
		if(((style != 2) && !result.size()) || (style == 2 && !count))	printf("NA\n");
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值