uva 10420 - List of Conquests
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid;=8&page;=show_problem&problem;=1361 题意:给n个带空格的字符串,第一个单词是国家,统计每个国家的字符串的个数。 思路:getline函数。。。find函数。。。substr函数。。。map…..
1/* ***********************************************
2Author :111qqz
3Created Time :2016年01月20日 星期三 19时26分09秒
4File Name :code/uva/10420.cpp
5************************************************ */
6
7#include <cstdio>
8#include <cstring>
9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33string str;
34int len;
35map<string,int>mp;
36map<string,int>::iterator it;
37int main()
38{
39 #ifndef ONLINE_JUDGE
40 freopen("code/in.txt","r",stdin);
41 #endif
42 int T;
43 cin>>T;
44 getchar();
45 mp.clear();
46 while (T--)
47 {
48 getline(cin,str);
49// cout<<str<<endl;
50 int pos = str.find(' ');
51 string cou = str.substr(0,pos);
52 // cout<<"country:"<<cou<<endl;
53 mp[cou]++;
54 }
55// cout<<mp.size()<<endl;
56
57 for ( it=mp.begin() ; it!=mp.end() ; it++)
58 {
59 cout<<it->fst<<" "<<it->second<<endl;
60 }
61
62
63 #ifndef ONLINE_JUDGE
64 fclose(stdin);
65 #endif
66 return 0;
67}