结构体排序题
注意点:
- 里程数需要累加,有可能某个会员不止一次乘坐飞机
- 输入输出最好用scanf不然会超时
#include <cstdio>
#include <algorithm>
#include <string>
#include <iostream>
#include <unordered_map>
using namespace std;
typedef pair<string, int> PSI;
unordered_map<string, int> mp;
const int N = 1e5+4;
PSI tem[N];
int main(){
int n, k;
scanf("%d%d",&n,&k);
string id;
char str[25];
int mile;
for(int i = 0; i < n; i++){
scanf("%s%d",str,&mile);
id = str;
if(mile < k) mile = k;
int t;
if(mp.count(id)){
t = mp[id];
}else{
t = i+1;
mp[id] = t;
}
tem[t].first = id;
tem[t].second += mile;
}
int m;
scanf("%d",&m);
while(m--){
scanf("%s", str);
id = str;
if(!mp[id]) puts("No Info");
else printf("%d\n", tem[mp[id]].second);
}
return 0;
}