hdu 统计难题(map)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251

map的强大之处,但是运行时间太长。

代码:

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <math.h>
 4 #include <algorithm>
 5 #include <iostream>
 6 #include <ctype.h>
 7 #include <iomanip>
 8 #include <queue>
 9 #include <map>
10 #include <stdlib.h>
11 using namespace std;
12 
13 map<string,int> M;
14 
15 int main(){
16     string x;
17     char a;
18     while(true){
19         scanf("%c",&a);
20         if(a=='
'){
21             scanf("%c",&a);
22             x="";   //字符串 x 清空
23         }
24         if(a=='
')break;
25         x+=a;
26         M[x]+=1;
27     }
28     while(cin>>x)
29         printf("%d
",M[x]);
30     return 0;
31 }
原文地址:https://www.cnblogs.com/wangmengmeng/p/4875789.html