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 |
除排序外和C0400004079写的一样,为什么wrong answer?救命啊!!!!!#include <stdio.h> #include <stdlib.h> main() { long count; long i,j,k,ir,first; long num[100002]; char tmp[200]; scanf("%ld",&count); for(i=1;i<=count;i++) { scanf("%s",tmp); for(j=0,k=0;tmp[j]!='\0';j++,k++) { if(tmp[j]>='A'&&tmp[j]<='P') tmp[j]=(char)((tmp[j]-'A')/3)+'2'; if(tmp[j]>='R'&&tmp[j]<='Y') tmp[j]=(char)((tmp[j]-'Q')/3)+'7'; tmp[k]=tmp[j]; if(tmp[k]=='-') k--; } tmp[k]='.'; num[i]=atol(tmp); } k=count/2+1; //堆排序 ir=count; while(1) { if(k>1) k--,first=num[k]; else { first=num[ir]; num[ir]=num[1]; ir--; if(ir<=1) break; } i=k; j=k+k; while(j<=ir) { if(j<ir&&num[j]<num[j+1]) j++; if(first<num[j]) { num[i]=num[j]; i=j; j=j+j; } else j=ir+1; } num[i]=first; } num[1]=first; ir=0; //输出 for(i=1,j=1;i<count;i++) { if(num[i]==num[i+1]) j++; if(num[i]!=num[i+1]||i==count-1) { if(j>1){ sprintf(tmp,"%07ld",num[i-1]); for(k=0;k<7;k++) { if(k==3) printf("-"); printf("%c",tmp[k]); } printf(" %ld",j); printf("\n"); j=1; ir=1; } } } if(ir==0) printf("No duplicates.\n"); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator