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 |
AC了,庆祝贴,代码贴上,呵呵,40MS,#include <stdio.h> #include <string.h> int main() { char a[101][51],temp[51]; int i,j,k,m,n,d[101]; for(i=0;i<101;i++){ d[i]=0; for(j=0;j<51;j++) a[i][j]='\0'; } scanf("%d %d",&n,&m); for(i=0;i<m;i++) scanf("%s",a[i]); for(i=0;i<m;i++){ for(j=0;j<n;j++) for(k=j+1;k<n;k++){ if(a[i][j]>a[i][k]) d[i]++; } } for(i=0;i<m;i++){ for(j=i+1;j<m;j++) { if(d[i]>d[j]) { strcpy(temp,a[i]); strcpy(a[i],a[j]); strcpy(a[j],temp); d[i]=d[i]+d[j]; d[j]=d[i]-d[j]; d[i]=d[i]-d[j]; } } } for(i=0;i<m;i++){ if(i>0) printf("\n"); printf("%s",a[i]); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator