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<iostream> using namespace std; int Partition(int a[], int ,int ); int Fastsort(int a[], int ,int ); int Swap(int&, int&); int unsort_Num(char * a,int n) { int count=0; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ if(a[i]>a[j]) count++; } } return count; } int main(void) { int n,m,i,ii,l,ln; cin>>n>>m; char **d= new char* [m]; for(i = 0;i<m;i++){ d[i] = new char [n]; cin>>d[i]; } int *unsortedness = new int[m]; int *flag = new int [m]; for(ii = 0;ii<m;ii++){ flag[ii]=0; unsortedness[ii]=0; unsortedness[ii]= unsort_Num(d[ii],n); } int *copy= new int [m]; for(ln=0;ln<m;ln++) copy[ln]=unsortedness[ln]; Fastsort(copy,0,m); for(l=1;l<=m;l++) { for(int p=0;p<m;p++) if(copy[l] == unsortedness[p] && flag[p]==0){ flag[p] = 1;//当数组有相同项时,flag跳过已经输出过的项。 cout<<d[p]<<endl; } } system("pause"); return 0; } int Partition(int a[], int p,int r) { int x = a[p]; int i = p-1; int j = r+1; while(1) { do{ j--; }while(a[j] > x); do{ i++; }while(a[i] < x); if(i<j){ Swap(a[i],a[j]); } else return j; } } int Fastsort(int a[], int p,int r) { if(p < r) { int q = Partition(a, p, r); Fastsort(a, p, q); Fastsort(a, q+1,r); } else return 0; } int Swap(int& a,int& b) { int temp =a; a = b; b = temp; return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator