Advertisement
Spocoman

02. Hospital

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