POJ 1002 - 487-3279 STL
先把不是标准格式的字符串变成标准格式
再输出出现两次以上的标准串和出现的次数
不然输出 "No duplicates."
1 #include <iostream> 2 #include <cstring> 3 #include <string> 4 #include <map> 5 #include <vector> 6 #include <algorithm> 7 using namespace std; 8 int n; 9 map<char,char> num; 10 map<string,int> mp; 11 string a; 12 char s[100005]; 13 vector<string> ans; 14 int main() 15 { 16 num.clear(); 17 mp.clear(); 18 ans.clear(); 19 num['A'] = num['B'] = num['C'] = '2'; 20 num['D'] = num['E'] = num['F'] = '3'; 21 num['G'] = num['H'] = num['I'] = '4'; 22 num['J'] = num['K'] = num['L'] = '5'; 23 num['M'] = num['N'] = num['O'] = '6'; 24 num['P'] = num['R'] = num['S'] = '7'; 25 num['T'] = num['U'] = num['V'] = '8'; 26 num['W'] = num['X'] = num['Y'] = '9'; 27 cin>>n; 28 for (int i = 1; i <= n; i++) 29 { 30 a.clear(); 31 cin>>s; 32 for (int i = 0; s[i] != '\0'; i++) 33 { 34 if(s[i]>='0' && s[i]<='9') a+=s[i]; 35 else if(s[i] >= 'A' && s[i] <= 'Z' && s[i] != 'Q' && s[i] != 'Z') 36 a+= num[s[i]]; 37 if(a.length() == 3) a+='-'; 38 } 39 if(a.length() == 8) 40 { 41 mp[a]++; 42 if(mp[a] == 2) ans.push_back(a); 43 } 44 } 45 sort(ans.begin(), ans.end()); 46 if(ans.size() == 0) 47 { 48 cout<<"No duplicates."<<endl; 49 } 50 else 51 { 52 for (int i = 0; i < ans.size(); i++){ 53 cout<<ans[i]<<" "<<mp[ans[i]]<<endl; 54 } 55 } 56 }
我自倾杯,君且随意