当前位置:   article > 正文

输入n个字符串字典序排序_字符串——字符串排序

实现n个字符串按字典排序c语言

Description

输入3个字符串,按字典序从小到大进行排序。

Input

输入数据有一行,分别为3个字符串,用空格分隔,每个字符串长度不超过100。

Output

输出排序后的三个字符串,用空格分隔。

Sample

Input

abcd cdef bcde

Output

abcd bcde cdef

实现

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int main()
  5. {
  6. int i, j, n = 3, min;
  7. char str[3][101], t[100];
  8. scanf("%s %s %s", str[0], str[1], str[2]);
  9. for(i = 0; i < n - 1; i++)
  10. {
  11. min = i;
  12. for(j = i + 1; j < n; j++)
  13. {
  14. if(strcmp(str[j], str[min]) < 0)
  15. min = j;
  16. }
  17. strcpy(t, str[i]);
  18. strcpy(str[i], str[min]);
  19. strcpy(str[min], t);
  20. }
  21. printf("%s %s %s", str[0], str[1], str[2]);
  22. return 0;
  23. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/651346
推荐阅读
相关标签
  

闽ICP备14008679号