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 ...
随机推荐
- HDU 1166 敌兵布阵(树状数组)
之前用过了线段树的做法,树状数组的也补上吧 #include<iostream> #include<cstdio> #include<cstring> using ...
- 关于WebAPI安全认证的问题
之前项目遇到了一个对外提供API的问题,有些粗浅的想法,抽空记录下. 以下所讨论的都是要解决:谁有资格调用这个API的问题(谁有权限进行这个操作的问题) 为了简化思路,就拿一个查看Java班级的学生举 ...
- n个List<Map>合并,Map中某属性值相等的value值相加
List<Map> maps1 =[{"bigtypes":100,"num":400},{"bigtypes":200,&qu ...
- STM32 IAP 在线升级详解(转)
源:http://blog.csdn.net/yx_l128125/article/details/12992773 (扩展-IAP主要用于产品出厂后应用程序的更新作用,考虑到出厂时要先烧写IAP ...
- html 自定义标签的作用
比如早期的时候,如果浏览器不支持 nav 这个标签的话, style标签中的样式 nav {color: yellow}会不起作用,字体不会变黄. 怎么处理兼容性呢? 用 javascript. 加上 ...
- HttpServletRequest.getServletContext()一直提示找不到,而引出的问题
开发j2ee项目的时候,需要用到servlet-api,如果使用了maven,web项目可以在pom.xml中手动加入所需jar包,达到与依赖j2ee libarary同样的功能.可问题来了: 1. ...
- Hibernate---基础配置
hibernate.cfg.xml里可以设置一个值显示更详细的sql语句: <property name="format_sql">true</property& ...
- javascript books
脑子里突然冒出这么一句话: “反射 是一种 代理!!!”,javascript ECMScript 6中也开始实现 Reflect 了. php的动态代理, 反射方面,在很多框架中都用到了.也是很多框 ...
- struts2使用iterator标签显示嵌套Map - 云自无心水自闲 - BlogJava
"> <s:iterator value="dataMap.keySet()" id="class"> ...
- Quick Cocos2dx Http通讯
服务端:Python 通讯协议:Http 参考文章: 1 用python实现一个基本的http server服务器 http://blog.sina.com.cn/s/blog_416e3063010 ...