You probably know that Alex is a very serious mathematician and he likes to solve serious problems. This is another problem from Alex.
You are given three nonnegative integers a, b, c. You have to arrange them in some order and put +, − or × signs between them to minimize the outcome of the resulting expression. You are not allowed to use unary minus and parentheses in the expression. There must be exactly one sign between every pair of neighbouring numbers. You should use standard order for performing operations (multiplication first, addition and subtraction then).
There are three lines with one integer in each line. The numbers are arranged in non-decreasing order (0 ≤ a ≤ b ≤ c ≤ 100).
Print one number — the minimal outcome.
| input | output |
|---|---|
1 2 3 |
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
using namespace std;
int main()
{
int b[5];
int i;
for(i = 0; i < 3; i++)cin >> b[i];
sort(b, b + 3);
int sum1 = b[0] - b[1] - b[2];
int sum2 = b[0] - b[1] * b[2];
cout << min(sum1, sum2) << endl;
return 0;
}
2067

被折叠的 条评论
为什么被折叠?



