如题:http://poj.org/problem?id=1002
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 254570 | Accepted: 45329 |
Description
The standard form of a telephone number is seven decimal digits with a hyphen between the third and fourth digits (e.g. 888-1200). The keypad of a phone supplies the mapping of letters to numbers, as follows:
A, B, and C map to 2
D, E, and F map to 3
G, H, and I map to 4
J, K, and L map to 5
M, N, and O map to 6
P, R, and S map to 7
T, U, and V map to 8
W, X, and Y map to 9
There is no mapping for Q or Z. Hyphens are not dialed, and can be added and removed as necessary. The standard form of TUT-GLOP is 888-4567, the standard form of 310-GINO is 310-4466, and the standard form of 3-10-10-10 is 310-1010.
Two telephone numbers are equivalent if they have the same standard form. (They dial the same number.)
Your company is compiling a directory of telephone numbers from local businesses. As part of the quality control process you want to check that no two (or more) businesses in the directory have the same telephone number.
Input
Output
No duplicates.
Sample Input
12 4873279 ITS-EASY 888-4567 3-10-10-10 888-GLOP TUT-GLOP 967-11-11 310-GINO F101010 888-1200 -4-8-7-3-2-7-9- 487-3279
Sample Output
310-1010 2 487-3279 4 888-4567 3
Source
WA了一晚上,发现
1.最终输入数据有16组,没有一组带Q,Z的
2.每行输入很长,可能有一堆没用的下划线(开200解决)
#include<iostream>
#include<cstring>
#include<cstring>
#include<algorithm>
#include<iomanip>
using namespace std;
#define N 100005
int a[N];
int convert(char ch) //把字符ch转换为其在手机上对应的数字键
{
if(ch=='A' || ch=='B' || ch=='C')
return 2;
if(ch=='D' || ch=='E' || ch=='F')
return 3;
if(ch=='G' || ch=='H' || ch=='I')
return 4;
if(ch=='J' || ch=='K' || ch=='L')
return 5;
if(ch=='M' || ch=='N' || ch=='O')
return 6;
if(ch=='P' || ch=='R' || ch=='S')
return 7;
if(ch=='T' || ch=='U' || ch=='V')
return 8;
if(ch=='W' || ch=='X' || ch=='Y')
return 9;
}
int main()
{
// freopen("C:\\Users\\Administrator\\Desktop\\ECNA99-real\\E\\E.13.dat","r",stdin);
// freopen("C:\\Users\\Administrator\\Desktop\\ECNA99-real\\E\\E.13.txt","w",stdout);
int T;
cin>>T;
int i,j;
int flag=0;
for(i=1;i<=T;i++)
{
char str[200];
scanf("%s",str);
int m=0;
int len=strlen(str);
for(j=0;j<len;j++)
{
if(str[j]=='Q'||str[j]=='Z')
{
m=-1;
break;
}
else if(str[j]>='0'&&str[j]<='9')
m=m*10+str[j]-'0';
else if(str[j]>='A'&&str[j]<='Z')
m=m*10+convert(str[j]);
}
a[i]=m;
}
sort(a+1,a+1+T);
for(i=1;i<T;i++)
{
int num=1;
while(a[i]!=-1&&a[i]==a[i+1])
{
num++;
i++;
}
if(num>1)
{
flag=1;
printf("%03d-%04d %d\n",a[i]/10000,a[i]%10000,num);
}
}
if(!flag)
printf("No duplicates.\n");
return 0;
}