COJ 1285 STL中的map每日三水(无限个输入按哪个快捷键得输出)

[STL]首富

Time Limit: 3000 ms     Memory Limit: 65536 KB
Total Submit: 129     Accepted: 39

Description
世界上有钱的人很多,但总会被评出一个世界首富。比如Bill Gates就多年被评为世界首富。

但是首富的钱是不固定的,有时候赚钱,有时候赔钱。

现在我们知道很多很多首富的多日收支情况,请问最后谁是首富?

假设他们都白手起家,初始财产为0。

Input
单组数据输入。每组数据包括若干行。最多1000行。以EOF结束。
每行包括包括一个字符串和一个整数。 字符串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

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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值