标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2185 Accepted Submission(s): 1064
1 #include <stdio.h> 2 #include <string.h> 3 #include <algorithm> 4 using namespace std; 5 6 struct ac 7 { 8 int s; 9 char str[55]; 10 }; 11 ac num[110]; 12 13 bool cmp(ac a, ac str) 14 { 15 return a.s < str.s; 16 } 17 18 int main() 19 { 20 char ch[55]; 21 int sum, total = 0; 22 int t, i, j, k, m, n; 23 scanf("%d", &t); 24 while(t--) 25 { 26 if(total != 0) 27 printf("\n"); 28 scanf("%d %d", &n, &m); 29 total++ ; 30 for(i=0; i<m; i++) 31 { 32 sum = 0; 33 scanf("%s", ch); 34 //puts(ch); 35 strcpy(num[i].str, ch); 36 //puts(num[i].str); 37 for(k=0; k<n-1; k++) 38 { 39 for(j=k+1; j<n; j++) 40 { 41 if(ch[k] > ch[j]) 42 sum++; 43 //printf("%d %d\n", k, sum); 44 } 45 } 46 num[i].s = sum; 47 } 48 sort(num, num+m, cmp); 49 for(i=0; i<m; i++) 50 printf("%s\n", num[i].str); 51 if(t!=0) 52 printf("\n"); 53 } 54 return 0; 55 }
标签:
原文地址:http://www.cnblogs.com/fengshun/p/4676339.html