The 11th Zhejiang Provincial Collegiate Programming Contest->Problem G:G - Ternary Calculation
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3782
题意:把输入的三元运算用计算机运算出来。
1 #include <bits/stdc++.h>
2 using namespace std;
3 int main() {
4 int t;
5 cin>>t;
6 while(t--) {
7 int a,b,c;
8 int s1=0;
9 char n,m;
10 cin>>a>>n>>b>>m>>c;
11 if(n=='*'||n=='/'||n=='%') {
12 if(n=='*')
13 s1=a*b;
14 else if(n=='/')
15 s1=a/b;
16 else
17 s1=a%b;
18 if(m=='*')
19 s1=s1*c;
20 else if(m=='/')
21 s1=s1/c;
22 else if(m=='%')
23 s1=(int)s1%c;
24 else if(m=='+')
25 s1=s1+c;
26 else if(m=='-')
27 s1=s1-c;
28 } else if(m=='*'||m=='/'||m=='%') {
29 if(m=='*')
30 s1=b*c;
31 else if(m=='/')
32 s1=b/c;
33 else if(m=='%')
34 s1=b%c;
35 if(n=='+')
36 s1=a+s1;
37 else if(n=='-')
38 s1=a-s1;
39
40 } else {
41 if(n=='+')
42 s1=a+b;
43 else if(n=='-')
44 s1=a-b;
45 if(m=='+')
46 s1=s1+c;
47 else if(m=='-')
48 s1=s1-c;
49 }
50 printf("%d\n",s1);
51
52 }
53 return 0;
54 }
我会一直在