| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
请各位大虾帮忙看看我的代码,我老WA,样例都过了,有没有什么诡异的数据?#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define SIZE 100
char tel[SIZE][8];
int n;
int comp(const void *elem1,const void *elem2)
{
return (strcmp((char *)elem1,(char *)elem2));
}
void print(int i)
{
int j;
for(j=0;j<3;j++)
{
printf("%c",tel[i][j]);
}
printf("-");
for(j=3;j<8;j++)
{
printf("%c",tel[i][j]);
}
}
void find()
{
int nod=0;
int i=0;
int j;
while(i<n)
{
j=i;
i++;
while(i<n&&(!strcmp(tel[i],tel[j]))) i++;
if(i-j>1)
{
print(j);
printf(" %d\n",i-j);
nod=1;
}
}
if(!nod)
{
printf("No duplicates.\n");
}
}
int main()
{
char stemp[150];
int i,j,k;
int l;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s",stemp);
l=strlen(stemp);
k=-1;
for(j=0;j<l;j++)
{
if(stemp[j]>='0'&&stemp[j]<='9')
{
k++;
tel[i][k]=stemp[j];
}
else if(stemp[j]>='A'&&stemp[j]<='C')
{
k++;
tel[i][k]='2';
}
else if(stemp[j]>='D'&&stemp[j]<='F')
{
k++;
tel[i][k]='3';
}
else if(stemp[j]>='G'&&stemp[j]<='I')
{
k++;
tel[i][k]='4';
}
else if(stemp[j]>='J'&&stemp[j]<='L')
{
k++;
tel[i][k]='5';
}
else if(stemp[j]>='M'&&stemp[j]<='O')
{
k++;
tel[i][k]='6';
}
else if(stemp[j]>='P'&&stemp[j]<='S')
{
k++;
tel[i][k]='7';
}
else if(stemp[j]>='T'&&stemp[j]<='V')
{
k++;
tel[i][k]='8';
}
else if(stemp[j]>='W'&&stemp[j]<='Y')
{
k++;
tel[i][k]='9';
}
}
tel[i][k+1]=0;
}
qsort(tel,n,8,comp);
find();
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator