zoj-3782-Ternary Calculation
来源:互联网 发布:vb 向上取整 编辑:程序博客网 时间:2024/03/29 15:22
Description
Complete the ternary calculation.
Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
There is a string in the form of "number1operatoranumber2operatorbnumber3". Each operator will be one of {'+', '-' , '*', '/', '%'}, and each number will be an integer in [1, 1000].
Output
For each test case, output the answer.
Sample Input
51 + 2 * 31 - 8 / 31 + 2 - 37 * 8 / 55 - 8 % 3
Sample Output
7-10113
Note
The calculation "A % B" means taking the remainder of A divided by B, and "A / B" means taking the quotient.
总共只有那么几种情况,也就两个操作符三个数,实在不行枚举也行
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int main() { int i,j,t,a,b,c,ans; char o1,o2; scanf("%d",&t); while(t--) { scanf("%d%*c%c%*c%d%*c%c%*c%d",&a,&o1,&b,&o2,&c); if((o1=='+'||o1=='-')&&(o2=='*'||o2=='/'||o2=='%')) { switch(o2) { case'*':ans=b*c;break; case'/':ans=b/c;break; case'%':ans=b%c; } switch(o1) { case'+':ans+=a;break; case'-':ans=a-ans; } } else { switch(o1) { case'+':ans=a+b;break; case'-':ans=a-b;break; case'*':ans=a*b;break; case'/':ans=a/b;break; case'%':ans=a%b; } switch(o2) { case'+':ans+=c;break; case'-':ans-=c;break; case'*':ans*=c;break; case'/':ans/=c;break; case'%':ans%=c; } } printf("%d\n",ans); } return 0; }
0 0
- ZOJ 3782 Ternary Calculation
- ZOJ 3782 Ternary Calculation
- ZOJ 3782 Ternary Calculation
- ZOJ 3782 Ternary Calculation
- zoj-3782-Ternary Calculation
- ZOJ 3782 Ternary Calculation【】
- ZOJ 3782Ternary Calculation(模拟)
- ZOJ Problem Set - 3782 Ternary Calculation
- ZOJ Ternary Calculation
- zoj 3782 Ternary Calculation(简单题,但有陷阱)
- ZOJ-3782-Ternary Calculation【11th浙江省赛】
- Ternary Calculation
- Ternary Calculation
- G、Ternary Calculation
- ZOJ3782:Ternary Calculation
- zoj3782 Ternary Calculation
- G.Ternary Calculation
- ZOJ3782-Ternary Calculation
- python 参数传递[打包与解包问题]
- zoj-3785-What day is that day?
- 进制转换
- C++第5次实验- 教师类
- linux下exit()和_exit()区别
- zoj-3782-Ternary Calculation
- mysql多实例
- Spring MVC 4 文件上传下载 Hibernate+MySQL例子 (带源码)
- SAR成像基础知识急救箱(二)关于离散傅里叶变换
- MTK当修改一些代码时,使用什么编译命令可以最有效率
- Django Mode
- zoj-3776-Pokemon Master
- hdoj-2109-Fighting for HDU
- Web前端性能优化(三)添加Expires头