您的位置:首页 > 其它

UVA 755 487--3279

2015-12-21 06:44 253 查看
分析:这个题就有点难度了,设置一个常量数组必不可少,<map>神器记录每个电话号码出现的次数即可。

UVA的题的格式真是让人一醉再醉,一跪再跪,空行,一定要读懂题意,看明白空行所在的位置。。。WA数次,该死的

空行

#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <cctype>
#include <cstring>
#include <list>

using namespace std;
int re[26]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,0,7,7,8,8,8,9,9,9,0};
int main()
{
map<string,int>cnt;
int T,n;
string str;
cin>>T;
getline(cin,str);
while(T--)
{
cnt.clear();
cin>>n;
getchar();
while (n--)
{
string s1;
getline(cin,str);
for (int j=0;j<str.size();j++)
{
if (str[j]=='-') continue;
else if (str[j]>='A'&&str[j]<='Z') s1+=(re[str[j]-'A']+'0');
else s1+=str[j];
}
s1.insert(3,1,'-');
if (!cnt.count(s1)) cnt[s1]=0;
cnt[s1]++;
}
int f=0;
map<string,int>::iterator it;
for (it=cnt.begin();it!=cnt.end();it++)
if (it->second!=1) {cout<<it->first<<" "<<it->second<<endl;f=1;}
if (!f)   cout<<"No duplicates."<<endl;
if (T!=0)cout<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: