Advertisement
Spocoman

06. Building (solutions with or not ternary operator)

Sep 11th, 2023 (edited)
2,772
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7.     int floorCount, floorFlatCount;
  8.     cin >> floorCount >> floorFlatCount;
  9.  
  10.     string appendix;
  11.  
  12.     for (int f = floorCount; f > 0; f--) {
  13.         if (f == floorCount) {
  14.             appendix = "L";
  15.         }
  16.         else if (f % 2 == 1) {
  17.             appendix = "A";
  18.         }
  19.         else {
  20.             appendix = "O";
  21.         }
  22.  
  23.         for (int n = 0; n < floorFlatCount; n++) {
  24.             cout << appendix << f << n << " ";
  25.         }
  26.         cout << endl;
  27.     }
  28.  
  29.     return 0;
  30. }
  31.  
  32. Решение с тернарен оператор:
  33.  
  34. #include <iostream>
  35.  
  36. using namespace std;
  37.  
  38. int main() {
  39.  
  40.     int floorCount, floorFlatCount;
  41.     cin >> floorCount >> floorFlatCount;
  42.  
  43.     string appendix;
  44.  
  45.     for (int f = floorCount; f > 0; f--) {
  46.         appendix =
  47.             f == floorCount ? "L" :
  48.             f % 2 == 1 ? "A" : "O";
  49.        
  50.         for (int n = 0; n < floorFlatCount; n++) {
  51.             cout << appendix << f << n << " ";
  52.         }
  53.         cout << endl;
  54.     }
  55.  
  56.     return 0;
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement