湖南工业大学创新实验室2015年新生赛(一)1009(重开)

分数统计

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 38   Accepted Submission(s) : 19

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

双十二的问题处理完了, Ikids 学长又遇到了一个
棘手的问题,现在Ikids学长有许多人员要统计他们
的总分数, 需要你帮忙, Ikids 学长怕问题太过
麻烦, 好心的把人员都编号了。

Input

输入包含多组输入

输入 M , M 表示 M条记录
每条记录包含两个整数,分别代表人的编号和分数
M < 1000
编号,分数 < 1e9 + 7;

Output

将所有被记录的人按照编号从小到大的方式
输出他们的 编号, 分数。

Sample Input

5
2 3
3 2
4 2
2 1
2 1

Sample Output

2 5
3 2
4 2

Author

Aoxuets
 
map的简单用法
#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
using namespace std;
map<string,int>q;
struct P
{
    string s;
    int num;
}hehe[10000];
bool cmd(P x,P y)
{
    if(x.s<y.s)
        return 1;

    return 0;
}
int main()
{
   int t;
   int i;
   string s;
   int num;
   while(cin>>t)
   {
       for(i=0;i<t;i++)
       {
          cin>>hehe[i].s>>hehe[i].num;
          q[hehe[i].s]+=hehe[i].num;
       }
      // cout<<q.size()<<endl;
       map<string,int>::iterator it;
       for(it=q.begin();it!=q.end();it++)
       {
           cout<<it->first<<" "<<it->second<<endl;
       }
       q.clear();
   }
   return 0;
}

  

posted @ 2015-11-25 21:39  樱花落舞  阅读(230)  评论(0编辑  收藏  举报