今天上课,老师教了小易怎么计算加法和乘法,乘法的优先级大于加法,但是如果一个运算加了括号,那么它的优先级是最高的。例如:
1 2 3 4 |
|
现在小易希望你帮他计算给定3个数a,b,c,在它们中间添加"+", "*", "(", ")"符号,能够获得的最大值。
输入描述:
一行三个数a,b,c (1 <= a, b, c <= 10)
输出描述:
能够获得的最大值
示例1
输入
1 2 3
输出
9
#include<iostream>
#include<cmath>
using namespace std;
int calculate(int x, int y, int z)
{
int a = x+y+z;
int b = x*y+z;
int c = x*y*z;
int d = (x+y)*z;
return max(max(a,b),max(c,d));
}
int main()
{
int x,y,z;
cin>>x>>y>>z;
int a = calculate(x,y,z);
int b = calculate(x,z,y);
int c = calculate(y,z,x);
cout<<max(max(a,b),c)<<endl;
return 0;
}