码迷,mamicode.com
首页 > 其他好文 > 详细

*字符串-03. 字符串的冒泡排序

时间:2014-08-19 23:39:25      阅读:325      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   for   ar   

 1 /*
 2  * Main.c
 3  * D3-字符串-03. 字符串的冒泡排序
 4  *  Created on: 2014年8月19日
 5  *      Author: Boomkeeper
 6  *******部分通过********
 7  */
 8 
 9 #include <stdio.h>
10 #include <string.h>
11 
12 int main(void){
13 
14     int N=0,K=0;//题目中的N、K
15 
16     scanf("%i %i",&N,&K);
17     getchar();
18     //读取字符串
19     char str[N][10];
20     int i;
21     for(i=0;i<N;i++){
22         scanf("%s",str[i]);
23         getchar();
24     }
25 
26     //冒泡排序
27     int j;
28     for(j=0;j<N;j++){
29         if(j>=K)
30             break;
31         int k;
32         for(k=0;k<N-j-1;k++){
33             if(str[k][0]>str[k+1][0]){
34                 char temp[10];
35                 strcpy(temp,str[k]);
36                 strcpy(str[k],str[k+1]);
37                 strcpy(str[k+1],temp);
38             }
39         }
40     }
41     //打印输出
42     int m;
43     for(m=0;m<N;m++){
44         printf("%s\n",str[m]);
45     }
46 
47     return 0;
48 }

 bubuko.com,布布扣

题目链接:

http://pat.zju.edu.cn/contests/basic-programming/%E5%AD%97%E7%AC%A6%E4%B8%B2-03

 

 

.

*字符串-03. 字符串的冒泡排序,布布扣,bubuko.com

*字符串-03. 字符串的冒泡排序

标签:style   blog   http   color   os   io   for   ar   

原文地址:http://www.cnblogs.com/boomkeeper/p/D3.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!