龟壳排序

 1 #include <stdio.h>
 2 #include <string.h>
 3 
 4 char tortName[200][80]   = {{0}};
 5 char tortSort[200][80]   = {{0}};
 6 
 7 int find(int x)
 8 {
 9     int i = 0;
10     
11     for(i = 0; i < 200; i++)
12     {
13         if(0 == memcmp(tortName[i], tortSort[x], 80))
14         {
15             return i;
16         }
17     }
18 }
19 
20 
21 int main(int argc, char *argv[])
22 {
23     int groupNum = 0;
24     int tortNum  = 0;
25     int i = 0;
26     int j = 0;
27     int p1 = 0;
28     int p2 = 0;
29     int firstMove = 0;
30     
31     scanf("%d", &groupNum);
32     
33     for(i = 0; i < groupNum; i++)
34     {
35         /*读入*/
36         scanf("%d", &tortNum);
37         for(j = 0; j < tortNum; j++)
38         {
39             scanf("%s", tortName[j]);            
40         }
41         
42         for(j = 0; j < tortNum; j++)
43         {
44             scanf("%s", tortSort[j]);            
45         }
46         
47         p1 = find(tortNum-1);
48         for(j = 0; j < tortNum - 1; j++)
49         {
50             p2 = find(tortNum-2-j);
51             if(p2 > p1)
52             {
53                 firstMove = tortNum-1-j;
54                 break;
55             }
56             p1 = p2;
57         }
58         
59         /*输出*/
60         for(i = 0; i < firstMove; i++)
61         {
62             printf("%s\n", tortSort[firstMove-i]);
63         }
64         
65         printf("\n");    
66     }
67 
68     return 0;
69 }

 

posted @ 2014-01-23 09:12  reasontom  阅读(224)  评论(0编辑  收藏  举报