P4414 ABC
Description
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 more pleasant viewing, we want to rearrange them in the given order.
Input format
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 format
Output the A, B, and C in the desired order on a single line, separated by single spaces.
Example
Case #1
Input
1 5 3
ABC
Output
1 3 5
Case #2
Input
6 4 2
CAB
Output
6 2 4
!!!!!!!!!!!!!!!!!!!!!!!!!!!
Coding
#include <iostream>
using namespace std;
void ss(int &n1,int &n2, int &n3) {
if(n1>n2){
int tmp = n1;
n1 = n2;
n2 = tmp;
}
if(n1>n3){
int tmp = n1;
n1 = n3;
n3 = tmp;
}
if(n2>n3){
int tmp = n2;
n2 = n3;
n3 = tmp;
}
return;
}
int o(char u) {
if(u=='A')
return 0;
else if(u=='B')
return 1;
else
return 2;
}
int rearrange() {
int num[3];
char q,w,e;
cin >> num[0] >> num[1] >> num[2];
cin >> q >> w >>e;
ss(num[0],num[1],num[2]);
cout << num[o(q)] << " " << num[o(w)] << " " << num[o(e)];
return 0;
}
What I learned
Sort three number
void ss(int &n1,int &n2, int &n3) {
if(n1>n2){
int tmp = n1;
n1 = n2;
n2 = tmp;
}
if(n1>n3){
int tmp = n1;
n1 = n3;
n3 = tmp;
}
if(n2>n3){
int tmp = n2;
n2 = n3;
n3 = tmp;
}
return;
}