这是一道字符串的问题,看起来很难,其实只要你思路清晰,就会知道些了!
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
const int maxn=100005;
char s[maxn];
int a[maxn];
int pp(char c)
{
if(c=='A'||c=='B'||c=='C')
return 2;
else if(c=='D'||c=='E'||c=='F')
return 3;
else if(c=='G'||c=='H'||c=='I')
return 4;
else if(c=='J'||c=='K'||c=='L')
return 5;
else if(c=='M'||c=='N'||c=='O')
return 6;
else if(c=='P'||c=='R'||c=='S')
return 7;
else if(c=='T'||c=='U'||c=='V')
return 8;
else if(c=='W'||c=='X'||c=='Y')
return 9;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int i,j;
int len;
int k=0;
memset(a,0,sizeof(a));
getchar();//一开始错在这里了,无语死了!
while(n--)
{
gets(s);
len=strlen(s);
int sum=0;
for(i=0; i<len; i++)
{
if(s[i]=='-'||s[i]=='Q'||s[i]=='Z')
continue;
if(s[i]>='0'&&s[i]<='9')
{
sum=sum*10+s[i]-'0';
}
else if(s[i]>='A'&&s[i]<='Z')
{
sum=sum*10+pp(s[i]);
}
}
a[k++]=sum;
}
sort(a,a+k);
i=0;
int flag=0;
while(i<k-1)
{
j=i;
while(a[i]==a[i+1])i++;
if(i!=j){printf("%03d-%04d %d\n",a[i]/10000,a[i]%10000,i-j+1);flag=1;}//题目要求输出不止一种表达形式
i++;
}
if(flag==0)
{
printf("No duplicates.\n");
}
}
return 0;
}