1002
写的很烂的版本
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
const int numberLength=9;
map<string,int>allphone;
int flags=0;
//typedef pair<string,int>PAIR;
/*vector<PAIR>vec;
int cmp(const PAIR& x, const PAIR& y)
{
return x.second < y.second;
}
*/
int have(char *argments)
{
map<string,int>::iterator it=allphone.find(argments);
if(it!=allphone.end())
{
it->second++;
flags=1;
}
else
{
allphone.insert(map<string,int>::value_type(argments,1));
}
return 0;
}
int action()
{
//freopen("d:\\a.txt","r",stdin);
int m = 0;
char temp = ' ';
char lines[9]="";
scanf("%d",&m);
getchar();//12后面有一个回车符
int inc = 0;
//注意getchar是从文件的输入stdin中读取数据, 而getc是从文件流中读取
while((temp=getchar())!=EOF)
{
//cout<<temp;
if(temp=='-')
{
temp=getchar();
// cout<<temp;
}
if(inc==3)lines[inc++]='-';
if(temp<='9'&&temp>='0')
{
lines[inc]=temp;
}
else if(temp=='A'||temp=='B'||temp=='C')
{
lines[inc]='2';
}
else if(temp=='D'||temp=='E'||temp=='F')
{
lines[inc]='3';
}
else if(temp=='G'||temp=='H'||temp=='I')
{
lines[inc]='4';
}
else if(temp=='J'||temp=='K'||temp=='L')
{
lines[inc]='5';
}
else if(temp=='M'||temp=='N'||temp=='O')
{
lines[inc]='6';
}
else if(temp=='P'||temp=='R'||temp=='S')
{
lines[inc]='7';
}
else if(temp=='T'||temp=='U'||temp=='V')
{
lines[inc]='8';
}
else if(temp=='W'||temp=='X'||temp=='Y')
{
lines[inc]='9';
}
else if(temp=='\n')
{
have(lines);
memset(lines,0,sizeof(lines));
inc=-1;
}
inc++;
}
/*cout<<endl;
for(int i=0; i<(*record); i++)
{
cout<<phone[i]<<"……"<<flags[i]<<endl;
}
*/
/*for(map<string,int>::iterator it=allphone.begin();it!=allphone.end();it++)
{
vec.push_back(make_pair(it->first,it->second));
}
*/
for(map<string,int>::iterator it=allphone.begin();it!=allphone.end();it++)
{
if(it->second>1)cout<<it->first<<" "<<it->second<<endl;
}
if(flags==0)cout<<"No duplicates" <<endl;
/*
sort(vec.begin(),vec.end(),cmp);
for(vector<PAIR>::iterator it=vec.begin();it!=vec.end();it++)
{
if((*it).second>1)
{
cout<<(*it).first<<" "<<(*it).second<<endl;
}
}
*/
}
//http://bbs.youkuaiyun.com/topics/310125656
//http://www.cnblogs.com/cszlg/archive/2013/03/10/2952807.html
整理之后,但是执行时间还是超时了
#include <iostream>
#include <map>
#include <stdio.h>
using namespace std;
map<string,int>phone;
char trans(char a)
{
string after = "";
for(int i=0; i<8; i++)
{
switch(a)
{
case 'A':
case 'B':
case 'C':
return '2';
case 'D':
case 'E':
case 'F':
return '3';
case 'G':
case 'H':
case 'I':
return '4';
case 'J':
case 'K':
case 'L':
return '5';
case 'M':
case 'N':
case 'O':
return '6';
case 'P':
case 'R':
case 'S':
return '7';
case 'T':
case 'U':
case 'V':
return '8';
case 'W':
case 'X':
case 'Y':
return '9';
default:
return a;
}
}
}
int main()
{
// freopen("d:\\a.txt","r",stdin);
int m = 0;
int len = 0;
int flag=0;
scanf("%d",&m);
for(int i=0; i<m; i++)
{
string line = "";
string aphone = "";
cin>>line;
len=line.length();
for(int j=0; j<len; j++)
{
if((line[j]<='Z'&&line[j]>='A' )||(line[j]<='9'&&line[j]>='0'))
{
aphone+=trans(line[j]);
}
}
phone[aphone]+=1;
}
for(map<string,int>::iterator it=phone.begin(); it!=phone.end(); it++)
{
if(it->second>1)
{
for(int i=0;i<7;i++)
{
cout<<it->first[i];
if(i==2)cout<<"-";
}
cout<<" "<<it->second<<endl;
flag=1;
}
}
if(flag==0)
{
cout<<"No duplicates."<<endl;
}
}