POJ1002

水,各种做法,可以hash什么的,c++的可以直接用map映射,需要注意的是众所周知STL非常之慢,还有cin也是,多年不写程序都忘了这些了,还有就是map里面的元素本来就是按照字典序排好的,不用sort了,否则加个sort会TLE

 1 #include<map>
 2 #include<cstdio>
 3 #include<vector>
 4 #include<cstdlib>
 5 #include<cstring>
 6 #include<iostream>
 7 #include<algorithm>
 8 using namespace std;
 9 const int N_MAX=100000+10,mp[26]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,-1,7,7,8,8,8,9,9,9,-1};
10 int n;map<string,int> cnt;char str[1000];string tmp;vector<string> vec;
11 int isdigit(char ch){ if ('0'<=ch && ch<='9') return 1;return 0; }
12 int isalpbet(char ch){ if ('A'<=ch && ch<='Z') return 1;return 0; }
13 int main(){
14     freopen("input","r",stdin);
15     scanf("%d", &n);
16     for (int i=1; i<=n; ++i){
17         scanf("%s", str); tmp=""; int len=strlen(str);
18         for (int it=0; it<len; ++it){
19             char ch=str[it];
20             if (isdigit(ch)){
21                 tmp+=ch;
22                 continue;
23             }
24             if (isalpbet(ch)){
25                 tmp+=char('0'+mp[ch-'A']);
26                 continue;
27             }
28         }
29         ++cnt[tmp];
30     }
31     int putout=0;
32     for (map<string,int>::iterator it=cnt.begin(); it!=cnt.end(); ++it){
33         string num=it->first;
34         if (it->second==1) continue;
35         putout=1;
36         cout<<num[0]<<num[1]<<num[2]<<"-"<<num[3]<<num[4]<<num[5]<<num[6]<<" "<<cnt[num]<<endl;
37     }
38     if (!putout) printf("No duplicates.\n");
39     return 0;
40 }
View Code

 

posted @ 2016-07-25 22:23  J_Harden  阅读(96)  评论(0)    收藏  举报