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题为啥老wa.但我试了好多答案都对的呀(附代码)#include"iostream" #include<string.h> using namespace std; struct tnode { char *p; int j; }; int partition(char (*tele_num)[8],int low,int high) { memcpy(tele_num[0],tele_num[low],8); while(low<high) { while(low<high&&strcmp(tele_num[high],tele_num[0])>=0) --high; if(low<high) memcpy(tele_num[low++],tele_num[high],8); while(low<high&&strcmp(tele_num[low],tele_num[0])<=0) ++low; if(low<high) memcpy(tele_num[high--],tele_num[low],8); } memcpy(tele_num[low],tele_num[0],8); return low; }; void Qsort(char (*tele_num)[8],int s,int t) { int pivotloc; if(s<t) { pivotloc=partition(tele_num,s,t); Qsort(tele_num,s,pivotloc-1); Qsort(tele_num,pivotloc+1,t); } }; int main() { int n,i,j,k,count=0; char (*tele_num)[8]; int *tn; scanf("%d",&n); fflush(stdin); tele_num=new char[n+1][8]; if(tele_num==NULL) { exit(0); } tn=new int[n]; if(tn==NULL) { exit(0); } for(i=0;i<n;i++) { tn[i]=n+1; } for(i=1;i<n+1;i++) { for(j=0;j<8;j++) { tele_num[i][j]=cin.get(); if(tele_num[i][j]=='\n') { tele_num[i][j]='\0'; break; } if(tele_num[i][j]=='-') { j--; } if(tele_num[i][j]>='A'&&tele_num[i][j]<='Z') { switch(tele_num[i][j]) { case 'A': case 'B': case 'C': tele_num[i][j]='2'; break; case 'D': case 'E': case 'F': tele_num[i][j]='3'; break; case 'G': case 'H': case 'I': tele_num[i][j]='4'; break; case 'J': case 'K': case 'L': tele_num[i][j]='5'; break; case 'M': case 'N': case 'O': tele_num[i][j]='6'; break; case 'P': case 'R': case 'S': tele_num[i][j]='7'; break; case 'T': case 'U': case 'V': tele_num[i][j]='8'; break; case 'W': case 'X': case 'Y': tele_num[i][j]='9'; break; } } } } Qsort(tele_num,1,n); tn[0]=1; for(i=1;i<n;i++) { j=i+1; if(strcmp(tele_num[i],tele_num[j])!=0) { count++; tn[count]=j; } } if(tn[n-1]!=n+1) { printf("No duplicates.\n"); } else { for(j=1;j<n;j++) { i=j-1; if(tn[j]-tn[i]>1) { for(k=0;k<=2;k++) printf("%c",tele_num[tn[i]][k]); printf("-"); for(k=3;k<7;k++) printf("%c",tele_num[tn[i]][k]); printf(" %d\n",tn[j]-tn[i]); } if(tn[j]-tn[i]==0) break; } } delete []tele_num; delete []tn; return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator