pku acm 1002

来源:互联网 发布:ubuntu切换中文输入法 编辑:程序博客网 时间:2024/05/17 01:15
#include <iostream>#include <vector>#include <string>#include <algorithm>using namespace std;string format(string s){int i = 0;for(i = 0; i < s.length(); i++){if(s[i] != '-'){switch(s[i]){case 'A':case 'B':case 'C':s[i] = '2';break;case 'D':case 'E':case 'F':s[i] = '3';break;case 'G':case 'H':case 'I':s[i] = '4';break;case 'J':case 'K':case 'L':s[i] = '5';break;case 'M':case 'N':case 'O':s[i] = '6';break;case 'P':case 'R':case 'S':s[i] = '7';break;case 'T':case 'U':case 'V':s[i] = '8';break;case 'W':case 'X':case 'Y':s[i] = '9';break;}}else{s.erase(i,1);i--;}}s.insert(3,1,'-');return s;}int main(){string s;vector<string> vs;int count,k;freopen("in.txt","r",stdin);cin>>count;k = count;while(k-- > 0){cin>>s;vs.push_back(format(s));}vector<string>::iterator it;if(count >= 1){sort(vs.begin(),vs.end());k = count = 0;s = vs[0];for(it = vs.begin(); it < vs.end(); it++){if(*it == s)count++;else{if(count > 1){cout<<s<<" "<<count<<endl;k = 1;}count = 1;s = *it;}}if(count > 1 && it == vs.end()){cout<<s<<" "<<count<<endl;k = 1;}if(k == 0)cout<<"No duplicates."<<endl;}    return 0; }

原创粉丝点击