Advertisement
Spocoman

07. Working Hours

Sep 4th, 2023
780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int hour;
  7.     cin >> hour;
  8.  
  9.     string dayOfWeek;
  10.     cin >> dayOfWeek;
  11.  
  12.     if (dayOfWeek != "Sunday" && hour >= 10 && hour <= 18) {
  13.         cout << "open" << endl;
  14.     }
  15.     else {
  16.         cout << "closed" << endl;
  17.     }
  18.    
  19.     return 0;
  20. }
  21.  
  22. Решение с тернарен оператор:
  23.  
  24. #include <iostream>
  25.  
  26. using namespace std;
  27.  
  28. int main() {
  29.     int hour;
  30.     cin >> hour;
  31.  
  32.     string dayOfWeek;
  33.     cin >> dayOfWeek;
  34.  
  35.     cout << (dayOfWeek != "Sunday" && hour >= 10 && hour <= 18 ? "open" : "closed") << endl;
  36.    
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement