字符串排序

来源:互联网 发布:手机点歌台软件 编辑:程序博客网 时间:2024/05/16 13:03

字符串排序

Problem Description


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


Input

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


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


abcd cdef bcde

Example Output


abcd bcde cdef

代码:

#include <stdio.h>#include <string.h>#define MAXN 1000+5int main(){    char s[3][MAXN], t[MAXN];    int i, j;    for(i = 0; i < 3; i++)    {        scanf("%s", &s[i]);    }    for(i = 0; i < 2; i++)    {        for(j = i; j < 3; j++)        {            if(strcmp(s[i], s[j]) > 0)            {                strcpy(t, s[i]);                strcpy(s[i], s[j]);                strcpy(s[j], t);            }        }    }    for(i = 0; i < 2; i++)    {        printf("%s ", s[i]);    }    printf("%s", s[2]);    return 0;}