Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int days;
- cin >> days;
- int treated = 0, untreated = 0, doctors = 7;
- int currentDayPatients;
- for (int i = 1; i <= days; i++) {
- cin >> currentDayPatients;
- if (untreated > treated && i % 3 == 0) {
- doctors++;
- }
- if (currentDayPatients > doctors) {
- treated += doctors;
- untreated += currentDayPatients - doctors;
- }
- else {
- treated += currentDayPatients;
- }
- }
- cout << "Treated patients: " << treated << "." << endl;
- cout << "Untreated patients: " << untreated << "." << endl;
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- using namespace std;
- int main() {
- int days;
- cin >> days;
- int treated = 0, untreated = 0, doctors = 7;
- int currentDayPatients;
- for (int i = 1; i <= days; i++) {
- cin >> currentDayPatients;
- untreated > treated && i % 3 == 0 ? doctors++ : doctors;
- currentDayPatients > doctors ? treated += doctors : treated += currentDayPatients;
- currentDayPatients > doctors ? untreated += currentDayPatients - doctors : untreated;
- }
- cout << "Treated patients: " << treated << ".\nUntreated patients: " << untreated << ".\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement