输入三个字符串,按字典序排序从小到大顺序输出这三个字符串的代码
时间: 2023-05-29 08:07:40 浏览: 75
string a, b, c;
cin >> a >> b >> c;
if (a > b) swap(a, b);
if (a > c) swap(a, c);
if (b > c) swap(b, c);
cout << a << " " << b << " " << c << endl;
相关问题
输入三个字符串,按字典序排序从小到大顺序输出这三个字符串的java代码
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
String str1 = "abc";
String str2 = "def";
String str3 = "ghi";
String[] arr = {str1, str2, str3};
Arrays.sort(arr);
for (String str : arr) {
System.out.println(str);
}
}
}
c++输入三个字符串,按由小到大的顺序输出,字典序
排序。
示例输入:
```
hello
world
apple
```
示例输出:
```
apple
hello
world
```
代码实现:
```python
s1 = input()
s2 = input()
s3 = input()
if s1 > s2:
s1, s2 = s2, s1
if s1 > s3:
s1, s3 = s3, s1
if s2 > s3:
s2, s3 = s3, s2
print(s1)
print(s2)
print(s3)
```
代码说明:
1. 首先输入三个字符串。
2. 使用 `if` 语句进行比较,将三个字符串按照字典序从小到大排序。
3. 最后输出排序后的结果。