Codeforces-479A

A. Expression

Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers abc on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:

  • 1+2*3=7
  • 1*(2+3)=5
  • 1*2*3=6
  • (1+2)*3=9

Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.

It's easy to see that the maximum value that you can obtain is 9.

Your task is: given ab and c print the maximum value that you can get.

Input

The input contains three integers ab and c, each on a single line (1 ≤ a, b, c ≤ 10).

Output

Print the maximum value of the expression that you can obtain.

Examples

input

1
2
3

output

9

input

2
10
3

output

60

题意:

自己输入三个数字a,b,c你可以使用 * + (),三种自由组合使其得到的运算结果最大。


题解:

就是暴力枚举三个数字由上面三种符号组合的最大值,切忌不要排序,排序,排序(重要的事说三遍),我最开始就是觉得排序将前两个数和与积进行比较然后乘上最大那个数求最大值显然是错误的;

如果你排序对下列样例将过不了:

6

7

1

输出:48

如果你从小到大排序将会得到:49。


代码: 

#include 

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

using namespace std;

typedef long long ll;
typedef pair PII;

const int N = 250;

int n, m, ans = 0x7f7f7f7f;
int arr[N], brr[N], crr[N];
int a, b, c;
string s;

int main()
{
     IOS;
     int max1;
     cin >> a >> b >> c;
     arr[0] = a + b + c;
	 arr[1] = (a + b) * c;
	 arr[2] = a + (b * c);
	 arr[3] = a * b + c;
	 arr[4] = a * (b + c);
	 arr[5] = a * b * c;
	 for (int i = 0; i < 6; i++)
	 {
		 max1 = max(max1, arr[i]);
	 }
	 cout << max1;
     return 0;
}

 

你可能感兴趣的:(c++)