Result: Accepted
Time: 4ms
Memory: 1756kB
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
using namespace std;
int T,a,b,c,t;
char x,y;
int main(){
scanf("%d",&T);
while(T--){
scanf("%d %c %d %c %d",&a,&x,&b,&y,&c);
if((x=='+'||x=='-')&&(y=='*'||y=='/'||y=='%')){
if(y=='*') t=b*c;
else if(y=='/') t=b/c;
else if(y=='%') t=b%c;
if(x=='+') t=a+t;
else if(x=='-') t=a-t;
}
else{
if(x=='+') t=a+b;
else if(x=='-') t=a-b;
else if(x=='*') t=a*b;
else if(x=='/') t=a/b;
else if(x=='%') t=a%b;
if(y=='+') t+=c;
else if(y=='-') t-=c;
else if(y=='*') t*=c;
else if(y=='/') t/=c;
else if(y=='%') t%=c;
}
printf("%d\n",t);
}
}