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 <stdlib.h> char data[1000][500] = {0}; struct Node { int sum; int num; }; Node mem[1000] = {0}; int cmp(const void *pa,const void *pb) { return ((Node *)pa)->sum - ((Node *)pb)->sum; } int main() { int i,j,k; int n,m; scanf("%d %d",&n,&m); for(i = 0;i<m;i++) { scanf("%s",data[i]); int sum = 0; for(j = 0;j<n;j++) { for(k = j+1;k<n;k++) if(data[i][k]<data[i][j]) sum++; } mem[i].sum = sum; mem[i].num = i; } qsort(mem,m,8,cmp); for(i = 0;i<m;i++) printf("%s\n",data[mem[i].num]); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator