zoj-3782-Ternary Calculation
题目链接
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5269
题目很简单,直接把所有情况列出来。
我的AC代码
#include<stdio.h>
int main()
{
int t;
int a,b,c;
char c1,c2;
int s;
scanf("%d",&t);
getchar();
while(t--)
{
scanf("%d",&a);
getchar();
scanf("%c",&c1);
scanf("%d",&b);
getchar();
scanf("%c",&c2);
scanf("%d",&c);
getchar();
if(c1=='*')
{
if(c2=='*')
s=a*b*c;
else if(c2=='/')
s=a*b/c;
else if(c2=='%')
s=a*b%c;
else if(c2=='+')
s=a*b+c;
else
s=a*b-c;
}
else if(c1=='/')
{
if(c2=='*')
s=a/b*c;
else if(c2=='/')
s=a/b/c;
else if(c2=='%')
s=a/b%c;
else if(c2=='+')
s=a/b+c;
else
s=a/b-c;
}
else if(c1=='%')
{
if(c2=='*')
s=a%b*c;
else if(c2=='/')
s=a%b/c;
else if(c2=='%')
s=a%b%c;
else if(c2=='+')
s=a%b+c;
else
s=a%b-c;
}
else if(c1=='+')
{
if(c2=='*')
s=a+b*c;
else if(c2=='/')
s=a+b/c;
else if(c2=='%')
s=a+b%c;
else if(c2=='+')
s=a+b+c;
else
s=a+b-c;
}
else
{
if(c2=='*')
s=a-b*c;
else if(c2=='/')
s=a-b/c;
else if(c2=='%')
s=a-b%c;
else if(c2=='+')
s=a-b+c;
else
s=a-b-c;
}
printf("%d\n",s);
}
return 0;
}
也可以利用栈的知识。
zoj-3782-Ternary Calculation的更多相关文章
- Ternary Calculation
Ternary Calculation Time Limit : /2000ms (Java/Other) Memory Limit : /65536K (Java/Other) Total Subm ...
- ZOJ 3782 G - Ternary Calculation 水
LINK:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3782 题意:给出3个数和两个符号(+-*/%) 思路:拿到题目还 ...
- The 11th Zhejiang Provincial Collegiate Programming Contest->Problem G:G - Ternary Calculation
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3782 题意:把输入的三元运算用计算机运算出来. ; ci ...
- 2012-2014 三年浙江 acm 省赛 题目 分类
The 9th Zhejiang Provincial Collegiate Programming Contest A Taxi Fare 25.57% (166/649) (水 ...
- 浙大月赛ZOJ Monthly, August 2014
Abs Problem Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge Alice and Bob is playing a ga ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- [LeetCode] Ternary Expression Parser 三元表达式解析器
Given a string representing arbitrarily nested ternary expressions, calculate the result of the expr ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- Ternary Expression Parser
Given a string representing arbitrarily nested ternary expressions, calculate the result of the expr ...
- OpenCASCADE Curve Length Calculation
OpenCASCADE Curve Length Calculation eryar@163.com Abstract. The natural parametric equations of a c ...
随机推荐
- 新手常见的python报错及解决方案
此篇文章整理新手编写代码常见的一些错误,有些错误是粗心的错误,但对于新手而已,会折腾很长时间才搞定,所以在此总结下我遇到的一些问题.希望帮助到刚入门的朋友们.后续会不断补充. 目录 1.NameErr ...
- column name is keyword from
mysql: select tablename.from from tablename; postgresql: select "from" from tablename; sql ...
- 想要学习Linux技术,先好好的读一本Linux书籍吧
忘记你在使用windows时的使用习惯和使用思维.学习Linux,一定要适应Linux的命令行界面,因为命令行才是Linux的真正魅力所在,而X-window或着说桌面环境也只是运行在命令行模式下的一 ...
- [iOS]C语言技术视频-07-函数的定义
下载地址: 链接: http://pan.baidu.com/s/1mgiWSqc 密码: 2q9k
- 关于iOS性能调优
性能调优一直都是作为高阶iOS开发者的一个入门门槛,下面我搜集了日常查阅资料中见到的各种高质量调优博文,仅供参考 UIKit性能调优实战讲解 iOS 高效添加圆角效果实战讲解
- hadoop hdfs uri详解
body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...
- DNS远程和DNS日志
三.rndc远程控制服务器 1.在被管理的服务器上生成密钥 # cd /var/named/chroot/etc # rndc-confgen -a -b 128 -k mrndc-key -c mr ...
- HUST 1371 Emergency relief
状态压缩. 每一个人所需的物品对应一个数字,统计一个每个数字有几个.每一种提供物品的状态也对应一个数字,然后暴力判断. #include<cstdio> #include<cstri ...
- Cdoefroces #354
A题 题意:给定一些数,然后求一次交换以后最大的数和最小的数之间的最大距离 分析:找到最大数和最小数的位置,然后判断是把位置大的移到最后还是把位置小的移到开始位置即可 #include <ios ...
- C#基础之操作字符串的方法
C#基础之操作字符串的方法 C#中封装的对字符串操作的方法很多,下面将常见的几种方法进行总结: 首先定义一个字符串str 1.str.ToCharArray(),将字符串转换成字符数组 2.str.S ...