Advertisement
Spocoman

01. Match Tickets

Sep 5th, 2023 (edited)
974
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     double budget;
  7.     cin >> budget;
  8.  
  9.     string category;
  10.     cin >> category;
  11.  
  12.     int people;
  13.     cin >> people;
  14.  
  15.     if (people <= 4) {
  16.         budget *= 0.25;
  17.     }
  18.     else if (people <= 9) {
  19.         budget *= 0.4;
  20.     }
  21.     else if (people <= 24) {
  22.         budget /= 2;
  23.     }
  24.     else if (people < 50) {
  25.         budget *= 0.6;
  26.     }
  27.     else {
  28.         budget *= 0.75;
  29.     }
  30.  
  31.     if (category == "VIP") {
  32.         budget -= 499.99 * people;
  33.     }
  34.     else {
  35.         budget -= 249.99 * people;
  36.     }
  37.  
  38.     cout.setf(ios::fixed);
  39.     cout.precision(2);
  40.  
  41.     if (budget >= 0) {
  42.         cout << "Yes! You have " << budget << " leva left." << endl;
  43.     }
  44.     else {
  45.         cout << "Not enough money! You need " << abs(budget) << " leva." << endl;
  46.     }
  47.  
  48.     return 0;
  49. }
  50.  
  51. Решение с тернарен оператор :
  52.  
  53. #include <iostream>
  54.  
  55. using namespace std;
  56.  
  57. int main() {
  58.     double budget;
  59.     cin >> budget;
  60.  
  61.     string category;
  62.     cin >> category;
  63.  
  64.     int people;
  65.     cin >> people;
  66.  
  67.     budget *=
  68.         people <= 4 ? 0.25 :
  69.         people <= 9 ? 0.4 :
  70.         people <= 24 ? 0.5 :
  71.         people < 50 ? 0.6 : 0.75;
  72.  
  73.     budget -= (category == "VIP" ? 499.99 : 249.99) * people;
  74.  
  75.     cout.setf(ios::fixed);
  76.     cout.precision(2);
  77.  
  78.     budget >= 0 ?
  79.         cout << "Yes! You have " << budget << " leva left." << endl :
  80.         cout << "Not enough money! You need " << abs(budget) << " leva." << endl;
  81.  
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement