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 |
求助..拜托了.有注释..想死了..先是TLE..改用快速排序后就出错了..弄了2天了....还是WA!!!!!!!#include<iostream> #include<iomanip> using namespace std; //转换 int map(char p) { if(p=='A'||p=='B'||p=='C') return 2; else if(p=='D'||p=='E'||p=='F') return 3; else if(p=='G'||p=='H'||p=='I') return 4; else if(p=='J'||p=='K'||p=='L') return 5; else if(p=='M'||p=='N'||p=='O') return 6; else if(p=='P'||p=='S'||p=='R') return 7; else if(p=='T'||p=='U'||p=='V') return 8; else if(p=='W'||p=='X'||p=='Y') return 9; } //快速排序 void run(int * pA,int left,int right) {int i,j,middle,temp; i=left;j=right; middle=pA[(i+j)/2]; do { while((pA[i]<middle)&&(i<right)) i++; while((pA[j]>middle) && (j>left)) j--; if(i<=j) {temp=pA[i];pA[i]=pA[j];pA[j]=temp;i++;j--;} }while(i<=j); if(left<j) run(pA,left,j); if(right>i) run(pA,i,right); } void QuickSort(int* pA,int Count) { run(pA,0,Count-1); } int main() {char p;int static k=0;int i,ptelnumA[50000]={-100},ptelnum[50000][2]={-55},num,re=0,work=0; //输入数据 cin>>num; for(i=0;i<num;i++) {ptelnumA[i]=0; for(k=0;k<7;k++) {cin>>p; if(p=='-') k--; else if(p>=48&&p<=57) {ptelnumA[i]*=10;ptelnumA[i]+=p-48;} else {ptelnumA[i]*=10;ptelnumA[i]+=map(p);} } } QuickSort(ptelnumA,num); //记录重复的部分 ptelnum[0][0]=ptelnumA[0]; ptelnum[0][1]=0; for(i=1,k=1;i<num;i++) { if(ptelnumA[i]==ptelnum[k-1][0]) {ptelnum[k-1][1]++;re=1;} else{ptelnum[k][0]=ptelnumA[i];ptelnum[k][1]=0;k++;} } if(re)//有重复的输出 for(i=0;i<k+1;i++) {if(ptelnum[i][1]) cout<<setfill('0')<<setw(3)<<ptelnum[i][0]/10000 <<'-'<<setfill('0')<<setw(4)<<ptelnum[i][0]%10000<<' '<<ptelnum[i][1]+1<<'\n'; } //没有重复的输出 else cout<<"No duplicates."; return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator