#include<iostream>
using namespace std;
int main()
{
char a, b, c;
cin >> a >> b >> c;
if (a <= b && b <= c) cout << a << " " << b << " " << c << endl;
else if ( a <= c && c<= b) cout << a << " " << c << " "<<b << endl;
else if ( b <= a && a <= c) cout << b << " " << a << " " << c << endl;
else if ( b <= c && c <= a) cout << b << " " << c << " " << a << endl;
else if ( c <=a && a <= b) cout << c << " " << a << " " << b << endl;
else cout << c << " " << b << " " << a << endl;
return 0;
}
题目描述
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
输入
三个字符,之间无空格。
输出
输出一行,字符中间用一个空格分开。
提交时说编译错误,求解
题目描述 输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符. 输入
答案:1 悬赏:50 手机版
解决时间 2021-02-20 14:34
- 提问者网友:听门外雪花风
- 2021-02-20 01:29
最佳答案
- 五星知识达人网友:孤独的牧羊人
- 2021-02-20 01:49
#include<iostream>
using namespace std;
int main()
{
char a, b, c, d;
cin >> a >> b >> c;
cout << "before sort: ";
cout << a << ' ' << b << ' ' << c << endl;
if (a > b) {d = a; a = b; b = d;}
if (b > c) {d = b; b = c; c = d;}
if (a > b) {d = a; a = b; b = d;}
cout << "after sort: ";
cout << a << ' ' << b << ' ' << c << endl;
return 0;
}
执行后:
asd
before sort: a s d
after sort: a d s
Press any key to continue
using namespace std;
int main()
{
char a, b, c, d;
cin >> a >> b >> c;
cout << "before sort: ";
cout << a << ' ' << b << ' ' << c << endl;
if (a > b) {d = a; a = b; b = d;}
if (b > c) {d = b; b = c; c = d;}
if (a > b) {d = a; a = b; b = d;}
cout << "after sort: ";
cout << a << ' ' << b << ' ' << c << endl;
return 0;
}
执行后:
asd
before sort: a s d
after sort: a d s
Press any key to continue
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯