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 |
0MS AC 贴个、、、、仅供参考#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> struct arr { char a[60]; }; void insertsort(int b[],int n,struct arr s[]) { int x,i,j; struct arr y; for(i=1;i<n;i++) { y=s[i]; x=b[i]; for(j=i-1;j>=0;j--) { if(x<b[j]) {b[j+1]=b[j]; s[j+1]=s[j];} else break; } b[j+1]=x; s[j+1]=y; } } int main(int argc, char *argv[]) { int i,j,t,n,m,b[110]={0}; struct arr s[110]; scanf("%d%d",&n,&m); for(i=0;i<m;i++) scanf("%s",s[i].a); for(i=0;i<m;i++) for(j=0;j<n-1;j++) for(t=j+1;t<n;t++) if(s[i].a[j]>s[i].a[t]) b[i]++; insertsort(b,m,s); for(i=0;i<m;i++) printf("%s\n",s[i].a); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator