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<stdio.h> #include<stdlib.h> int main() { char s[51][101]; int num[51][101]; int flag[51]; int i,j,k,m,n;int min; scanf("%d%d",&m,&n); getchar(); for(i=0;i<n;i++){ scanf("%s",&s[i]); getchar(); for(j=0;j<m;j++){ num[i][j]=0; for(k=j+1;k<m;k++) if(s[i][j]>s[i][k])++num[i][j]; } } for(i=0;i<n;i++) for(j=1;j<m;j++) num[i][0]+=num[i][j];//讲逆序数累加到num首位 /* for(i=0;i<n;i++){//打印计算的num数组 for(j=0;j<m;j++){ printf("%d ",num[i][j]); } printf("\n"); } */ for(i=0;i<n;i++) flag[i]=1; for(i=0;i<n;i++) { min=200; for(j=0;j<n;j++){ if(num[j][0]<min&&flag[j]) { min=num[j][0]; k=j; } } flag[k]=0; printf("%s\n",s[k]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator