HDU4287-STL模拟水题

一场2012天津网络预选赛的题,签到题。

但是还是写了三四十分钟,C++和STL太不熟悉了,总是编译错误不知道怎么解决。

一开始用的Char [] 后来改成了string,STL和string搭配起来才好用啊。

 1 #include <algorithm>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <ctype.h>
 5 #include <cstdlib>
 6 #include <cstdio>
 7 #include <vector>
 8 #include <string>
 9 #include <queue>
10 #include <stack>
11 #include <cmath>
12 #include <set>
13 #include <map>
14 
15 using namespace std;
16 
17 int N,M,T;
18 map <string ,int> dic; 
19 string list[5010];
20 int table[]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};
21 int main()
22 {
23     cin >> T;
24     string s;
25     while(T--)
26     {
27         cin >> N >> M;
28         for(int i=0;i<N;i++) {
29             cin >> list[i];
30         }
31         dic.clear();
32         for(int i=0;i<M;i++)
33         {
34             cin >> s;
35             string num;
36             for(int k=0;k < (int)s.size();k++)
37             {
38                 num += table[s[k]-'a'] + '0';
39             }
40             //cout << num << endl;
41             map<string ,int>::iterator it = dic.find(num);
42             if(it == dic.end()){
43                 dic.insert(make_pair(num,1));
44             }
45             else
46                 it->second++;
47         }
48         map<string , int>::const_iterator notFound(dic.end());
49         map<string , int>::const_iterator pos;
50         for(int i=0;i<N;i++)
51         {
52             if((pos = dic.find(list[i])) == notFound)
53                 printf("0
");
54             else
55                 printf("%d
",pos->second);
56         }
57     }    
58 }
原文地址:https://www.cnblogs.com/helica/p/4783609.html