今天上课,老师教了小易怎么计算加法和乘法,乘法的优先级大于加法,但是如果一个运算加了括号,那么它的优先级是最高的。例如:
1 2 3 4 |
|
现在小易希望你帮他计算给定3个数a,b,c,在它们中间添加"+", "*", "(", ")"符号,能够获得的最大值。
//#include<stdc++.h>
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;
int Max(int a, int b, int c)//暴力枚举法,列举每一种可能性。。。。
{
vector<int> Count;
int temp = 0;
int count_1 = a + b + c;
int count_2 = a*b*c;
int count_3 = a*b*c;
int count_4 = (a + b)*c;
Count.push_back(count_1);
Count.push_back(count_2);
Count.push_back(count_3);
Count.push_back(count_4);
for (int i = 0; i < Count.size(); i++)
{
if (Count[i]>temp)
temp = Count[i];
}
return temp;
}
int main()
{
int q, w, e;
int result;
while (cin >> q >> w >> e)
{
result = 0;
int count_1 = Max(q, w, e);
int count_2 = Max(w, e, q);
result = count_1 > count_2 ? count_1 : count_2;
cout << result << endl;
}
//std::cin.get;
system("pause");
return 0;
}