[STL]首富
Time Limit: 3000 ms Memory Limit: 65536 KBTotal Submit: 129 Accepted: 39
Description
世界上有钱的人很多,但总会被评出一个世界首富。比如Bill Gates就多年被评为世界首富。
但是首富的钱是不固定的,有时候赚钱,有时候赔钱。
现在我们知道很多很多首富的多日收支情况,请问最后谁是首富?
假设他们都白手起家,初始财产为0。
但是首富的钱是不固定的,有时候赚钱,有时候赔钱。
现在我们知道很多很多首富的多日收支情况,请问最后谁是首富?
假设他们都白手起家,初始财产为0。
Input
单组数据输入。每组数据包括若干行。最多1000行。以EOF结束。
每行包括包括一个字符串和一个整数。 字符串A表示某富翁的名字,整数B表示富翁该日的收支金额。
(A的长度1 <= A.length() <= 50, -100000<=B<=100000)
每行包括包括一个字符串和一个整数。 字符串A表示某富翁的名字,整数B表示富翁该日的收支金额。
(A的长度1 <= A.length() <= 50, -100000<=B<=100000)
Output
输出首富的名字和财产金额。
Sample Input
dreamfox 30
xkey 2324
pmonkey 2342
dreamfox 23123
xkey 2332
dreamfox 12455
xkey 2324
pmonkey 2342
dreamfox 23123
xkey 2332
dreamfox 12455
Sample Output
dreamfox 35608
Hint
<map>
这道题还是比较容易的,但是有无限个输入的时候,不知道按哪个快捷键得到输出……
#include <iostream>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
int main()
{
map<string,int>p;
map<string,int>::iterator it;
string a,s;
int i,j,max=-1000000000;
char b[51];
while(scanf("%s%d",b,&i)!=EOF)
{
a=b;
it=p.find(a);
if(it==p.end()) p[a]=i;
else p[a]+=i;
}
for(it=p.begin();it!=p.end();it++)
if(max<it->second)
{
s=it->first;
j=it->second;
max=it->second;
}
cout<<s<<' '<<j<<endl;
return 0;
}