杭电2000-----ASCII码排序C++版

ASCII码排序
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 248964 Accepted Submission(s): 97835
Problem Description
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。
Output
对于每组输入数据,输出一行,字符中间用一个空格分开。
Sample Input
qwe
asd
zxc
Sample Output
e q w
a d s
c x z
Author
lcy`
Source
C语言程序设计练习(一)

#include<iostream>
using namespace std;
void f(char a,char b,char c)
{
    if(a<b&&a<c&&b<c)
    cout<<a<<" "<<b<<" "<<c<<endl;
    else if(a<b&&a<c&&c<b)
        cout<<a<<" "<<c<<" "<<b<<endl;
        else if(b<a&&b<c&&a<c)
            cout<<b<<" "<<a<<" "<<c<<endl;
            else if(b<a&&b<c&&c<a)
                cout<<b<<" "<<c<<" "<<a<<endl;
            else if(c<a&&c<b&&a<b)
                cout<<c<<" "<<a<<" "<<b<<endl;
            else if(c<a&&c<b&&b<a)
                cout<<c<<" "<<b<<" "<<a<<endl;
}
int main()
{
    char a,b,c;
    while(cin>>a>>b>>c)
    {
        f(a,b,c);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43289087/article/details/88580348