poj 1002(487-3279)STL中的map
#include<stdio.h> #include<string> #include<map> #include<algorithm> #include<iostream> using namespace std; string s; string ss; map<char ,char>mc; map<string, int>ms; map<string, int>::iterator it; int main() { mc['A']='2'; mc['P']='7'; mc['B']='2'; mc['R']='7'; mc['C']='2'; mc['S']='7'; mc['D']='3'; mc['T']='8'; mc['E']='3'; mc['U']='8'; mc['F']='3'; mc['V']='8'; mc['G']='4'; mc['W']='9'; mc['H']='4'; mc['X']='9'; mc['I']='4'; mc['Y']='9'; mc['J']='5'; mc['K']='5'; mc['L']='5'; mc['M']='6'; mc['N']='6'; mc['O']='6'; int _case; ms.clear(); scanf("%d",&_case); while(_case--) { ss.clear(); s.clear(); cin>>s; for(int i=0; i<s.size(); i++) { if('A'<=s[i]&&s[i]<='Z') { ss+=mc[s[i]]; } else if('0'<=s[i]&&s[i]<='9') { ss+=s[i]; //printf("%c",s[i]); } } ss.insert(ss.begin()+3,'-'); //cout<<ss<<endl; ms[ss]++; } int k=0; for(it=ms.begin(); it!=ms.end(); it++) if(it->second>1)k=1,cout<<it->first<<' '<<it->second<<endl; if(k==0)printf("No duplicates. \n"); return 0; }