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 |
代码!#include <stdio.h> #include <string.h> typedef struct string { char str[100]; int sort; }string; string s[105]; int main() { int m,n,ans,i,j,k,temp; char st[100]; scanf("%d %d",&m,&n); for(i=0;i<n;i++) { scanf("%s",s[i].str); ans=0; for(j=0;j<m;j++) for(k=j+1;k<m;k++) if(s[i].str[j]>s[i].str[k]) ans++; s[i].sort=ans; } for(i=0;i<n;i++) { k=i; for(j=i+1;j<n;j++) if(s[k].sort<s[j].sort) k=j; if(k!=j) { temp=s[i].sort; s[i].sort=s[k].sort; s[k].sort=temp; strcpy(st,s[i].str); strcpy(s[i].str,s[k].str); strcpy(s[k].str,st); } } for(i=n-1;i>=0;i--) printf("%s\n",s[i].str); return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator