首页 > 其他 > 详细

字串的连接最长路径查找

时间:2016-06-19 23:02:46      阅读:402      评论:0      收藏:0      [点我收藏+]

题目描述

  给定n个字符串,请对n个字符串按照字典序排列。 

输入描述

  输入第一行为一个正整数n(1≤n≤1000),下面n行为n个字符串(字符串长度≤100),字符串中只含有大小写字母。

输出描述

  数据输出n行,输出结果为按照字典序排列的字符串。

输入样例

9
cap
to
cat
card
two
too
up
boat
boot

输出样例

boat
boot
cap
card
cat
to
too
two
up

测试代码

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 #include <assert.h>
 5 
 6 int cmp(const void *p, const void *q)
 7 {
 8     return strcmp(*(char **)p, *(char **)q);
 9 }
10 
11 int main(void)
12 {
13     char **p = NULL;
14     int n, i;
15     scanf("%d", &n);
16     p = (char **)malloc(n * sizeof(char *));
17     assert(p != NULL);
18     for (i = 0; i < n; i++)
19     {
20         p[i] = (char *)malloc(105 * sizeof(char));
21         assert(p[i] != NULL);
22         scanf("%s", p[i]);
23     }
24     qsort(p, n, sizeof(p[0]), cmp);
25     for (i = 0; i < n; i++)
26     {
27         puts(*(p + i));
28     }
29     return 0;
30 }

 

字串的连接最长路径查找

原文:http://www.cnblogs.com/maxin/p/5599012.html

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