题目链接

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的更多相关文章

  1. Ternary Calculation

    Ternary Calculation Time Limit : /2000ms (Java/Other) Memory Limit : /65536K (Java/Other) Total Subm ...

  2. ZOJ 3782 G - Ternary Calculation 水

    LINK:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3782 题意:给出3个数和两个符号(+-*/%) 思路:拿到题目还 ...

  3. The 11th Zhejiang Provincial Collegiate Programming Contest->Problem G:G - Ternary Calculation

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3782 题意:把输入的三元运算用计算机运算出来. ;          ci ...

  4. 2012-2014 三年浙江 acm 省赛 题目 分类

    The 9th Zhejiang Provincial Collegiate Programming Contest A    Taxi Fare    25.57% (166/649)     (水 ...

  5. 浙大月赛ZOJ Monthly, August 2014

    Abs Problem Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge Alice and Bob is playing a ga ...

  6. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  7. [LeetCode] Ternary Expression Parser 三元表达式解析器

    Given a string representing arbitrarily nested ternary expressions, calculate the result of the expr ...

  8. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  9. Ternary Expression Parser

    Given a string representing arbitrarily nested ternary expressions, calculate the result of the expr ...

  10. OpenCASCADE Curve Length Calculation

    OpenCASCADE Curve Length Calculation eryar@163.com Abstract. The natural parametric equations of a c ...

随机推荐

  1. mr本地运行的几种模式

    MR程序的几种提交运行模式 本地模型运行 1/在windows的eclipse里面直接运行main方法,就会将job提交给本地执行器localjobrunner执行 ----输入输出数据可以放在本地路 ...

  2. PAT (Advanced Level) 1040. Longest Symmetric String (25)

    暴力. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ]; ...

  3. USACO Section 1.2 Name That Number 解题报告

    题目 题目描述 在一个农场里面,每一头牛都有一个数字编号,但是现在这些牛不喜欢这种编号,它们想把这些数字编号转化成为可以接受的字母的形式.数字与字母的转换表如下: 2: A,B,C 5: J,K,L ...

  4. smarty的ASSIGN()函数

    http://blog.sina.com.cn/s/blog_6721f25c01011qdj.html 主要是把程序里面的值付给模板,因为使用smarty时,模板里面是没有PHP代码的,无法显示在操 ...

  5. TOCContro控件

    TOCControl控件使用的是用伙伴控件中的数据地图,它控制图层是否在伙伴控件空显示以及和伙伴控件在符号上保持一致,TOCControl为用户提供了一个交互式的环境,如果TOCControl控件的伙 ...

  6. php自学笔记3

    -------补充--------建议定义常量时,判断常量名是否被定义,用defined()判断,返回布尔型if(!defined("POEM")){//没定义过 define(& ...

  7. perties类的操作

    http://www.cnblogs.com/bakari/p/3562244.html perties类的操作   知识学而不用,就等于没用,到真正用到的时候还得重新再学.最近在看几款开源模拟器的源 ...

  8. js动画(三)

    咳咳咳咳,感冒了感冒了,鼻塞,蓝瘦啊!嘴巴也开裂,哎,心疼自己.想到这是第三只唇膏了!只怪,放荡不倔爱自由, 行驶在冷风路上么,北风那个吹啊吹啊吹啊,好了,发神经发完了,接下来进入正题,严肃脸.(字数 ...

  9. POJ 1015 Jury Compromise

    感觉此题略难...... 背包问题.据说有一种二维DP的写法是错的.亲测,背包做法无误. dp[i][j][k]表示前i个物品,选择j个,差值为k的情况下获得的最大总和 dp[i][j][k]=max ...

  10. Linux系统开机启动流程

    (来源学习Linux时,自己做的笔记) Linux系统有7个运行级别(runlevel)运行级别0:系统停机状态,系统默认运行级别不能设为0,否则不能正常启动运行级别1:单用户工作状态,root权限, ...