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 |
总是Sample对,Result:Wrong Answer 。 谁能帮我看看呢。Source Problem Id:1007 User Id:Judas Memory:28K Time:0MS Language:C++ Result:Wrong Answer Source #include<iostream.h> #include<string.h> #include <malloc.h> int a[101]; void merge(int a[],int *temp,int l,int m,int r) { int i,j,k; for(i=m+1;i>l;i--)temp[i-1]=a[i-1]; for(j=m;j<r;j++)temp[r+m-j]=a[j+1]; for(k=l;k<=r;k++) { if(temp[i]<temp[j]) a[k]=temp[i++]; else a[k]=temp[j--]; } } void mergesort(int a[],int *temp,int l,int r) { int m=(l+r)/2; if(r<=l)return; mergesort(a,temp,l,m); mergesort(a,temp,m+1,r); merge(a,temp,l,m,r); } void main() { int n,m,i,j,k,flag[101],f=0,l,ff; char s[101][51]; cin>>n>>m; memset(flag,m,sizeof(flag)); for(i=0;i<m;i++) { for(j=0;j<n;j++) cin>>s[i][j]; s[i][50]=0; for(j=0;j<n-1;j++) for(l=0;l<n-j;l++) if (s[i][j+l]<s[i][j]) s[i][50]++; a[i]=s[i][50]; //cout<<a[i]<<endl; } int length=m; int *temp=(int*)malloc(sizeof(int)*length); mergesort(a,temp,0,length-1); cout<<endl; for(i=0;i<m;i++) { //cout<<a[i]<<endl; for(j=0;j<m;j++) { ff=0; if ( s[j][50]==a[i] ) { for(l=0;l<f;l++) if (j==flag[l]) ff=1; if (1!=ff) { for(k=0;k<n;k++) cout<<s[j][k]; flag[f]=j;f++; cout<<endl; continue; } } } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator