Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int tabs, salary;
- cin >> tabs >> salary;
- string apps;
- for (int i = 0; i < tabs && salary > 0; i++) {
- cin >> apps;
- if (apps == "Facebook") {
- salary -= 150;
- }
- else if (apps == "Instagram") {
- salary -= 100;
- }
- else if (apps == "Reddit") {
- salary -= 50;
- }
- }
- if (salary > 0) {
- cout << salary << endl;
- }
- else {
- cout << "You have lost your salary." << endl;
- }
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int tabs, salary;
- cin >> tabs >> salary;
- string apps;
- for (int i = 0; i < tabs && salary > 0; i++) {
- cin >> apps;
- salary -=
- apps == "Facebook" ? 150 :
- apps == "Instagram" ? 100 :
- apps == "Reddit" ? 50 : 0;
- }
- cout << (salary > 0 ? to_string(salary) : "You have lost your salary.") << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement