北大ACM题1002,求大神指导,为什么运行超时或错误,求解释!!!
#include <stdio.h>#include <string.h>
#include <stdlib.h>
int d[100002]={0};
char a[100002][100]; //输入数组
char b[100002][100]; //输入后去除'-'的数组
int main()
{
int i,j,k,n,min;
char c[100];
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s",a[i]);
for(k=0,j=0; ;j++)
{
if(a[i][j]=='A' || a[i][j]=='B' || a[i][j]=='C')
{
a[i][j]='2';
}
if(a[i][j]=='D' || a[i][j]=='E' || a[i][j]=='F')
{
a[i][j]='3';
}
if(a[i][j]=='G' || a[i][j]=='H' || a[i][j]=='I')
{
a[i][j]='4';
}
if(a[i][j]=='J' || a[i][j]=='K' || a[i][j]=='L')
{
a[i][j]='5';
}
if(a[i][j]=='M' || a[i][j]=='N' || a[i][j]=='O')
{
a[i][j]='6';
}
if(a[i][j]=='P' || a[i][j]=='R' || a[i][j]=='S')
{
a[i][j]='7';
}
if(a[i][j]=='T' || a[i][j]=='U' || a[i][j]=='V')
{
a[i][j]='8';
}
if(a[i][j]=='W' || a[i][j]=='X' || a[i][j]=='Y')
{
a[i][j]='9';
}
if(a[i][j]!='-')
{
b[i][k]=a[i][j];
k++;
}
if(a[i][j]=='\0')
{
break;
}
}
} //n个字符串输入
char e[100]={0};
int t;
for(i=0;i<n;i++)
{
for(j=i;j<n-1;j++)
{
if(strcmp(b[i],b[j+1])==0)
{
d[i]++;
strcpy(b[j+1],e);
}
}
}
int x;
for(x=0,i=0;i<n;i++)
{
min=i;
for(j=i;j<n-1;j++)
{
if(d[min]!=0 && d[j+1]!=0)
{
if(strcmp(b[min],b[j+1])>0)
{
min=j+1;
}
}
}
strcpy(c,b[i]);
strcpy(b[i],b[min]);
strcpy(b[min],c);
t=d[i];
d[i]=d[min];
d[min]=t;
if(strcmp((b[i]),e)!=0 && d[i]!=0)
{
for(j=7;j>3;j--)
{
b[i][j]=b[i][j-1];
}
b[i][j]='-';
printf("%s %d\n",b[i],d[i]+1);
x++;
}
}
if(x==0)
{
printf("No duplicates.");
}
return 0;
}