【HDOJ】1251 统计难题

使用STL实现。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <string>
 5 #include <map>
 6 using namespace std;
 7 
 8 int main() {
 9     char ch;
10     string str="";
11     map<string, int> words;
12 
13     while (1) {
14         scanf("%c", &ch);
15         if (ch == '\n') {
16             scanf("%c", &ch);
17             str = "";
18         }
19         // two consecutive '\n' then break;
20         if (ch == '\n')
21             break;
22         str += ch;
23         words[str]++;
24     }
25 
26     while (cin>>str)
27         printf("%d\n", words[str]);
28 
29     return 0;
30 }

 

posted on 2014-04-07 22:59  Bombe  阅读(123)  评论(0编辑  收藏  举报

导航