Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- double budget, cash;
- cin >> budget;
- int volume;
- cin >> volume;
- string name;
- for (int i = 0; i < volume; i++) {
- cin.ignore();
- getline(cin, name);
- cin >> cash;
- if (name == "Thrones") {
- cash /= 2;
- }
- else if (name == "Lucifer") {
- cash *= 0.6;
- }
- else if (name == "Protector") {
- cash *= 0.7;
- }
- else if (name == "TotalDrama") {
- cash *= 0.8;
- }
- else if (name == "Area") {
- cash *= 0.9;
- }
- budget -= cash;
- }
- if (budget >= 0) {
- printf("You bought all the series and left with %.2f lv.\n", budget);
- }
- else {
- printf("You need %.2f lv. more to buy the series!\n", abs(budget));
- }
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- double budget, cash;
- cin >> budget;
- int volume;
- cin >> volume;
- string name;
- for (int i = 0; i < volume; i++) {
- cin.ignore();
- getline(cin, name);
- cin >> cash;
- cash *=
- name == "Thrones" ? 0.5 :
- name == "Lucifer" ? 0.6 :
- name == "Protector" ? 0.7 :
- name == "TotalDrama" ? 0.8 :
- name == "Area" ? 0.9 : 1;
- budget -= cash;
- }
- budget >= 0 ?
- printf("You bought all the series and left with %.2f lv.\n", budget) :
- printf("You need %.2f lv. more to buy the series!\n", abs(budget));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement