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.....
/* ***********************************************
Author :111qqz
Created Time :2016年01月20日 星期三 19时26分09秒
File Name :code/uva/10420.cpp
************************************************ */
1#include <cstdio>
2#include <cstring>
3#include <iostream>
4#include <algorithm>
5#include <vector>
6#include <queue>
7#include <set>
8#include <map>
9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6string str;
7int len;
8map<string,int>mp;
9map<string,int>::iterator it;
10int main()
11{
12 #ifndef ONLINE_JUDGE
13 freopen("code/in.txt","r",stdin);
14 #endif
15 int T;
16 cin>>T;
17 getchar();
18 mp.clear();
19 while (T--)
20 {
21 getline(cin,str);
22// cout<<str<<endl;
23 int pos = str.find(' ');
24 string cou = str.substr(0,pos);
25 // cout<<"country:"<<cou<<endl;
26 mp[cou]++;
27 }
28// cout<<mp.size()<<endl;
1 for ( it=mp.begin() ; it!=mp.end() ; it++)
2 {
3 cout<<it->fst<<" "<<it->second<<endl;
4 }
1 #ifndef ONLINE_JUDGE
2 fclose(stdin);
3 #endif
4 return 0;
5}