轻敌了,想得太简单,后来脑子短路被困在了死循环里,捣鼓了一阵
用map一一映射保存结果,注意中间过程也要保存,被题干坑了一次,以后一定先认真审题然后敲
一开始没想明白,直接做复杂了。。
http://codeforces.com/problemset/page/47
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define ll long long
#define mod 1000000007
#define inf 0x3f3f3f3f
using namespace std;
struct node
{
string s;
int x;
}a[1005];
int main()
{
int n;
scanf("%d",&n);
map<string, int> m;
map<string, bool> bol;
string name[1005];
int cnt = 0;
int maxy = -inf;
string s;
int tmp;
for(int i = 1; i <= n; i ++)
{
cin>>s>>tmp;
m[s] += tmp;
if(! bol[s])
{
name[++ cnt] = s;
bol[s] = 1;
}
a[i].s = s;
a[i].x = m[s];
}
maxy = -inf;
string ans1;
for(int i = 1; i <= cnt; i ++)
{
if(maxy < m[name[i]])
{
ans1 = name[i];
maxy = m[name[i]];
}
}
//int cnt1 = 0;
map<string, bool> ans;
for(int i = 1; i <= cnt; i ++)
{
if(m[name[i]] == maxy)
{
ans[name[i]] = 1;
}
}
for(int i = 1; i <= n; i ++)
{
if(ans[a[i].s])
{
if(a[i].x >= maxy)
{
cout<<a[i].s<<endl;
break;
}
}
}
return 0;
}