题目描述
You will be given three integers A, B and C. The numbers will not be given in that exact order, but we do know that A is less than B and B less than C. In order to make for a more pleasant viewing, we want to rearrange them in the given order.
输入格式
The first line contains three positive integers A, B and C, not necessarily in that order. All three numbers will be less than or equal to 100. The second line contains three uppercase letters ‘A’, ‘B’ and ‘C’ (with no spaces between them) representing the desired order.
输出格式
Output the A, B and C in the desired order on a single line, separated by single spaces.
题意翻译
【题目描述】
三个整数分别为 A,B,CA,B,C。这三个数字不会按照这样的顺序给你,但它们始终满足条件:A < B < CA<B<C。为了看起来更加简洁明了,我们希望你可以按照给定的顺序重新排列它们。
【输入格式】
第一行包含三个正整数 A,B,CA,B,C,不一定是按这个顺序。这三个数字都小于或等于 100100。第二行包含三个大写字母 AA、BB 和 CC(它们之间没有空格)表示所需的顺序。
【输出格式】
在一行中输出 AA,BB 和 CC,用一个 (空格)隔开。
#include<bits/stdc++.h>
using namespace std;
int main() {
int arr[3];
char A, B, C;
for (int i = 0; i < 3; i++) {
cin >> arr[i];
}//输入三个数字
cin >> A >> B >> C;
/*for (int i = 0; i < 2; i++) {//冒泡排序
for (int j = 0; j < 2; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}*/
sort(arr, arr + 3);//sort排序函数
cout << arr[A - 'A'] <<" " << arr[B - 'A'] <<" " << arr[C - 'A'] << endl;//利用ascll编码
system("pause");
return 0;
}
学习过程:刚开始做的时候有点麻,毕竟是个什么都不会刚刚学的人,先是输入三个是,新手无脑int+cin,刚开始没有定义数组,后来显示定义数组存储三个数字,便于后面调用,然后题意是有从小到大排序的,所以就用了冒泡排序,当然很笨了,后来问了别人+看别人写的代码,用来sort函数,最后输出的时候我刚开始是很懵逼的,没什么经验,然后因为输入的是大写字母,可以使用ascll编码求得下标,借此调得数组存储的数字然后输出,据说很水,主要是我啥都不懂。