LINK:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3782
题意:给出3个数和两个符号(+-*/%)
思路:拿到题目还以为是要写波兰表达式,仔细一看固定的数和固定的符号,直接if判断好了
/** @Date : 2017-03-23-21.31
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version :
*/
#include<bits/stdc++.h>
#define LL long long
#define PII pair
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;
int main()
{
int T;
cin >> T;
while(T--)
{
int a, b, c;
char o1[2], o2[2];
int t = 0, ans = 0;
scanf("%d %s%d %s%d", &a, o1, &b, o2, &c);
//cout << a << o1 << b << o2 << c << endl;
if(o1[0] != '*' && o1[0] != '/' && o1[0] != '%' && o2[0] != '+' && o2[0] != '-')
{
if(o2[0] == '*')
t = b * c;
else if(o2[0] == '/')
t = b / c;
else if(o2[0] == '%')
t = b % c;
if(o1[0] == '+')
t = a + t;
else if(o1[0] == '-')
t = a - t;
}
else
{
if(o1[0] == '+')
t = a + b;
else if(o1[0] == '-')
t = a - b;
else if(o1[0] == '*')
t = a * b;
else if(o1[0] == '/')
t = a / b;
else if(o1[0] == '%')
t = a % b;
if(o2[0] == '+')
t = t + c;
else if(o2[0] == '-')
t = t - c;
else if(o2[0] == '*')
t = t * c;
else if(o2[0] == '/')
t = t / c;
else if(o2[0] == '%')
t = t % c;
}
//cout << 5 % 8 % 2 << endl;
printf("%d\n", t);
}
return 0;
}