首页 > 其他 > 详细

龟壳排序

时间:2014-01-23 10:55:51      阅读:359      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 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 }
bubuko.com,布布扣

龟壳排序

原文:http://www.cnblogs.com/reasontom/p/3530639.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!