JosepRivaille

P57315: ABC

Feb 21st, 2015
2,049
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //Precondició: Introduïm 3 nombres i l'ordre desitjat
  5. //Postcondició: Obtenim els nombres ordenats
  6.  
  7. int main() {
  8.   int x, y, z;
  9.   cin >> x >> y >> z;
  10.   string o;
  11.   cin >> o; //ordre
  12.   int A, B, C; //gran, mitjà, petit
  13.   C = x;
  14.   if (y > x) {
  15.     if (z > y) {
  16.       C = z;
  17.       B = y;
  18.       A = x;
  19.     }else if (z < y && z > x) {
  20.       C = y;
  21.       B = z;
  22.       A = x;
  23.     }else {
  24.       C = y;
  25.       B = x;
  26.       A = z;
  27.     }
  28.   }else {
  29.     if (z > x) {
  30.       C = z;
  31.       B = x;
  32.       A = y;
  33.     }else if (z < x && z > y) {
  34.       B = z;
  35.       A = y;
  36.     }else {
  37.       B = y;
  38.       A = z;
  39.     }
  40.   }
  41.   if (o == "ABC") cout << A << ' ' << B << ' ' << C << endl;
  42.   if (o == "ACB") cout << A << ' ' << C << ' ' << B << endl;
  43.   if (o == "BAC") cout << B << ' ' << A << ' ' << C << endl;
  44.   if (o == "BCA") cout << B << ' ' << C << ' ' << A << endl;
  45.   if (o == "CAB") cout << C << ' ' << A << ' ' << B << endl;
  46.   if (o == "CBA") cout << C << ' ' << B << ' ' << A << endl;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment