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 的code#include <stdio.h> #include <string.h> int m,n; // m test line with the length of n; int disorder(char *s) { int i,j,count = 0; for(i = 0; i < n-1; i++) for(j = i+1; j < n; j++) { if(s[j] < s[i] ) count ++; } return count; } int main() { int order[60]; char data[105][60]; while(scanf("%d%d",&n,&m) == 2 ) { int i,j; for(i = 0; i < m; i++) { scanf("%s",data[i]); order[i] = disorder(data[i]); } for(i = 0; i < m - 1; i++) // sort { bool changed = false; for(j = 0; j < m - i - 1; j++) { if(order[j+1] < order[j]) { changed = true; char s[105]; strcpy(s,data[j]); strcpy(data[j],data[j+1]); strcpy(data[j+1],s); int temp =order[j+1]; order[j+1] = order[j]; order[j] = temp; } } //if(!changed) break; } for(i = 0; i < m; i++) printf("%s\n",data[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