POJ 1007

 1 #include <stdio.h>
2 #include <stdlib.h>
3
4 char d[100][51];
5 struct node
6 {
7 int p;
8 int r;
9 };
10
11 node s[100];
12
13 int cmp( constvoid*a, constvoid*b)
14 {
15 return ((node*)a)->r - ((node*)b)->r;
16 }
17 int DNAsort(char a[],int n)
18 {
19 int count =0;
20 for(int i =0; i < n; i++)
21 for(int j = i+1; j < n; j++)
22 if(a[i] > a[j])
23 count++;
24 return count;
25 }
26 int main()
27 {
28 int n, m;
29 freopen("1.txt", "r", stdin);
30 scanf("%d %d", &n, &m);
31 for(int i =0; i < m; i++)
32 {
33 scanf("%s", d[i] );
34 s[i].r = DNAsort( d[i],n);
35 s[i].p = i;
36 }
37 qsort(s, m, sizeof(s[0]), cmp);
38 for(int i =0; i < m; i++)
39 printf("%s\n", d[ s[i].p ]);
40 return0;
41 }

反复的提醒自己,编码细节很重要!!!算法很简单,问题是qsort的细节搞了我N久。。。太久不写程序完全生手了。。。。勤加练习!!!!

原文地址:https://www.cnblogs.com/ShaneZhang/p/2129567.html