Task
In the supermarket of electronics, if you believe in TV commercials, there is a system of discounts: from two purchased goods fully paid only the cost of a higher-value product, and the other is provided free of charge. What amount of money is enough to pay for the purchase of three goods, if the price of each is known.
Input data:
Three natural numbers [latex]a, b, c[/latex] are prices of three products [latex]\left(1 ≤ a, b, с ≤ 10000\right)[/latex].
Output data:
Purchase cost.
Tests
# | Input data | Output data |
---|---|---|
1 | 2 2 2 | 4 |
2 | 78 2 45 | 80 |
3 | 452 89 88 | 540 |
4 | 50 4 67 | 71 |
5 | 15 37 20 | 52 |
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#include <iostream> using namespace std; int main() { int a, b,c, s=0; // "s" used as an auxiliary variable to store the amount of money cin>>a>>b>>c; if (a>=b && a>=c) { s=a; if (b>=c) { s+=c; } else s+=b; } else if (b>=a && b>=c) { s=b; if (a>=c) { s+=c; } else s+=a; } else if (c>=a && c>=b) { s=c; if (a>=b) { s+=b; } else s+=a; } cout<<s; return 0; } |
Solution of the problem
Algorithm: you will have to pay the highest price, so let’s find it at first and save it in the variable s. Next, you need to select the product for free receipt, which you put in a couple of the most expensive. To obtain the least amount of money, the remaining goods must be the cheapest.
Links
The task at e-olymp
The decision code at ideone
Расставь около && пробелы, чтобы не было целым текстом.
Исправила, спасибо.
Спасибо, исправила.
Хорошо. Принято.