| ||||||||||
| 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 | |||||||||
大神求助,1002,runtime error,学习中#include<string.h>
#include<stdio.h>
#include<malloc.h>
void exchange(char s,char *t)
{
if(s=='A'||s=='B'||s=='C')
*t='2';
if(s=='D'||s=='E'||s=='F')
*t='3';
if(s=='G'||s=='H'||s=='I')
*t='4';
if(s=='J'||s=='K'||s=='L')
*t='5';
if(s=='M'||s=='N'||s=='O')
*t='6';
if(s=='P'||s=='R'||s=='S')
*t='7';
if(s=='T'||s=='U'||s=='V')
*t='8';
if(s=='W'||s=='X'||s=='Y')
*t='9';
}
int Cs(char *a ,char *b)
{
int i=0,j=0;
while(a[i]!='\0')
{
if(a[i]=='-'||a[i]=='Q'||a[i]=='Z')
{
j=i;
while(a[j]!='\0')
{
a[j]=a[j+1];
j++;
}
}
else
i++;
}
i=0;
while(b[i]!='\0')
{
if(b[i]=='-'||b[i]=='Q'||b[i]=='Z')
{
j=i;
while(b[j]!='\0')
{
b[j]=b[j+1];
j++;
}
}
else
i++;
}
i=j=0;
while(a[i]!='\0'&&b[i]!='\0')
{
if(a[i]>=65&&a[i]<90)
exchange(a[i],&a[i]);
if(b[i]>=65&&b[i]<90)
exchange(b[i],&b[i]);
i++;
}
if(!strcmp(a,b))
return 1;
else
return 0;
}
int Same(char *a,char *b)
{
if(Cs(a,b))//转换字母为数字判定
return 1;
else
return 0;
}
int main()
{
int n,i,count=1,cur,all=0,del=0,ii=0,iout=0,out_count[10000]={0},k,c=0;
char *a[100000];
char *out[100000];
char *temp;
int tem;
scanf("%d",&n);
for(i=0;i<n;i++)
{
a[i]=(char*)malloc(sizeof(char *));
scanf("%s",a[i]);
/*
while((a[i][c]=getchar())!='\n'&&c<=7)
{
if((a[i][c]>=65&&a[i][c]<=80)||(a[i][c]>=82&&a[i][c]<=89))
c++;
}
c=0;
*/
}
all=n;
for(cur=0;cur<all;cur++)
{
for(i=cur+1;i<all;i++)
{
if(Same(a[cur] ,a[i]))
{
for(del=i;del<all-1;del++)
{
a[del]=a[del+1];
}
count++;
i--;
all--;
}
}
if(count>=2)
{
out[iout]=(char*)malloc(sizeof(char *));
out[iout]=a[cur];
out_count[iout]=count;
iout++;
count=1;
}
else
count=1;
}
k=iout;
if(iout==0)
printf("No duplicates.");
else
{
while(k>0)
{
for(i=0;i<k-1;i++)
{
if(strcmp(out[i],out[i+1])==1)//升序排列
{
temp=out[i+1];
out[i+1]=out[i];
out[i]=temp;
tem=out_count[i+1];
out_count[i+1]=out_count[i];
out_count[i]=tem;
}
}
k--;
}
for(i=0;i<iout;i++)
{
printf("%c",out[i][0]);
printf("%c",out[i][1]);
printf("%c",out[i][2]);
printf("-");
printf("%c",out[i][3]);
printf("%c",out[i][4]);
printf("%c",out[i][5]);
printf("%c ",out[i][6]);
printf("%d",out_count[i]);
printf("\n");
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator