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 |
我的想法拿错了啊程序如下:(oj判断为wrong answer,我们先不考虑时间复杂度吧,高手们,先把wrong answer搞掉,或者哪位好心人给几个典型测试数据也可以的) #include<stdio.h> void main() { int n,m,i,j,k,s[100],l; char a[100][51]; scanf("%d%d",&n,&m); for(i=0;i<100;i++) s[i]=0; getchar(); for(i=0;i<m;i++) gets(a[i]); for(l=0;l<n;l++)//分别求a[l]的逆序数,记录在s[i]中 { for(i=0;i<n-1;i++) { k=i; for(j=k+1;j<n;j++) if(a[l][k]>a[l][j]) s[l]++; } } for(i=0;i<m-1;i++)//每次找出最小的s[i],输出a[i],并将s[i]置为-1 { for(k=0;s[k]==-1;k++); for(j=k+1;j<m;j++) if(s[j]!=-1&&s[k]>s[j]) k=j; s[k]=-1; printf("%s\n",a[k]); } for(k=0;s[k]==-1;k++); printf("%s\n",a[k]); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator