1153 Decode Registration Card of PAT (25 分)

版本1

这个题,怎么说呢?巨TM恶心不过分吧。
排序尽量用结构体吧,vector靠不住。今天不是type==3的时候,我偏要用vector保存pair类型来排序,不然早就过了。
还有就是字符转数字的时候没有减去字符0,导致直接算的ASCII码值。

#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <algorithm> 
#include <unordered_map>
#include <map>
using namespace std;
const int N = 1e4+5;
typedef pair<int, int> PII;
unordered_map<string, PII> mp;
struct node{
	string pat;
	int score;
}E[N], A[N], B[N], T[N];
struct stu{
	int site, num;
}X[N];

bool cmp(node &a, node &b){
	if(a.score != b.score) return a.score > b.score;
	else return a.pat < b.pat;
}
bool cmp1(stu a, stu b){
	if(a.num != b.num) return a.num > b.num;
	return a.site < b.site;
}

int main(){
	int n, m, cnta=0, cntb=0, cntt=0;
	string temp, str;
	scanf("%d%d", &n, &m);
	for(int i = 0; i < n; i++){
		cin>>E[i].pat>>E[i].score;
		temp = E[i].pat.substr(1,3);
		mp[temp].second += E[i].score;
		mp[temp].first++;
		if(E[i].pat[0]=='A') A[cnta].pat = E[i].pat, A[cnta].score = E[i].score, cnta++;
		else if(E[i].pat[0]=='B') B[cntb].pat = E[i].pat, B[cntb].score = E[i].score, cntb++;
		else  T[cntt].pat = E[i].pat, T[cntt].score = E[i].score, cntt++;
	}
	int type;
	char C;
	string site, date;
	for(int i = 1; i <= m; i++){
		scanf("%d", &type);
		getchar();
		if(type == 1){
			cin>>C;
			printf("Case %d: %d %c\n",i,type, C);
			if(C=='A') {
				if(cnta == 0){
					puts("NA");
					continue;
				}
				sort(A, A + cnta, cmp);
				for(int j = 0; j < cnta; j++){
					cout<<A[j].pat<<" "<<A[j].score<<endl;
				}
			}else if(C == 'B'){
				
				if(cntb == 0){
					puts("NA");
					continue;
				}
				
				sort(B,B+cntb, cmp);
				for(int j = 0; j < cntb; j++){
					cout<<B[j].pat<<" "<<B[j].score<<endl;
				}
			}else{
				if(cntt == 0){
					puts("NA");
					continue;
				}
				sort(T,T+cntt, cmp);
				for(int j = 0; j < cntt; j++){
					cout<<T[j].pat<<" "<<T[j].score<<endl;
				}
			}
		}else if(type == 2){
			cin>>site;
			printf("Case %d: %d %s\n",i,type, site.c_str());
			if(mp.count(site)) printf("%d %d\n", mp[site].first, mp[site].second);
			else puts("NA");
			
		}else{
			
			cin>>date;
			
			printf("Case %d: %d %s\n",i,type, date.c_str());
			
			unordered_map<int, int> has;
			for(int v = 0; v < n; v++){
				temp = E[v].pat.substr(4, 6);
				if(temp == date){
					int t = (E[v].pat[1] - '0')*100+(E[v].pat[2] - '0')*10+E[v].pat[3]-'0';
					has[t]++;
				}
			}
			
			if(!has.size()) puts("NA");
			else{
				int id = 0;
				for(auto it: has){
					X[id].site = it.first;
					X[id].num = it.second;
					id++;
				}
				sort(X, X+id,cmp1);
				for(int z = 0; z < id; z++){
					cout<<X[z].site<<" "<< X[z].num<<endl;
				}
			}
		}
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值