您的位置:首页 > 其它

poj 1002

2012-03-14 15:50 218 查看
问题:487-3297
链接:http://poj.org/problem?id=1002
#include<iostream>
#include<map>#include<algorithm>#include<cctype>#include<string>using namespace std;map<string,int> tell;string change(string str){string sub="";for(int i=0;i<str.length();i++){if(isdigit(str[i])){sub.append(1,str[i]);}else{if(str[i]=='A'||str[i]=='B'||str[i]=='C'){sub.append(1,'2');}if(str[i]=='D'||str[i]=='E'||str[i]=='F'){sub.append(1,'3');}if(str[i]=='G'||str[i]=='H'||str[i]=='I'){sub.append(1,'4');}if(str[i]=='J'||str[i]=='K'||str[i]=='L'){sub.append(1,'5');}if(str[i]=='M'||str[i]=='N'||str[i]=='O'){sub.append(1,'6');}if(str[i]=='P'||str[i]=='R'||str[i]=='S'){sub.append(1,'7');}if(str[i]=='T'||str[i]=='U'||str[i]=='V'){sub.append(1,'8');}if(str[i]=='W'||str[i]=='X'||str[i]=='Y'){sub.append(1,'9');}}}str ="";str = str.append(sub.substr(0,3)).append(1,'-').append(sub.substr(3,4));return str;}int main(){int count = 0;string str;cin>>count;while(count--){cin>>str;str = change(str);++tell[str];}map<string,int>::iterator it = tell.begin();int num = 0;while(it!=tell.end()){if((it->second)>1){cout<<it->first<<" "<<it->second<<endl;num++;}it++;}if(num == 0)cout<<"No duplicates."<<endl;return 0;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: