赞
踩
输入3个字符串,按字典序从小到大进行排序。
输入数据有一行,分别为3个字符串,用空格分隔,每个字符串长度不超过100。
输出排序后的三个字符串,用空格分隔。
Input
abcd cdef bcde
Output
abcd bcde cdef
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main()
- {
- int i, j, n = 3, min;
- char str[3][101], t[100];
- scanf("%s %s %s", str[0], str[1], str[2]);
- for(i = 0; i < n - 1; i++)
- {
- min = i;
- for(j = i + 1; j < n; j++)
- {
- if(strcmp(str[j], str[min]) < 0)
- min = j;
- }
- strcpy(t, str[i]);
- strcpy(str[i], str[min]);
- strcpy(str[min], t);
- }
- printf("%s %s %s", str[0], str[1], str[2]);
- return 0;
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。