HDU 1170 Balloon Comes!

来源:互联网 发布:淘宝助理交易管理没有 编辑:程序博客网 时间:2024/06/05 02:52

Balloon Comes!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20356    Accepted Submission(s): 7673


Problem Description
The contest starts now! How excited it is to see balloons floating around. You, one of the best programmers in HDU, can get a very beautiful balloon if only you have solved the very very very... easy problem.
Give you an operator (+,-,*, / --denoting addition, subtraction, multiplication, division respectively) and two positive integers, your task is to output the result. 
Is it very easy? 
Come on, guy! PLMM will send you a beautiful Balloon right now!
Good Luck!
 

Input
Input contains multiple test cases. The first line of the input is a single integer T (0<T<1000) which is the number of test cases. T test cases follow. Each test case contains a char C (+,-,*, /) and two integers A and B(0<A,B<10000).Of course, we all know that A and B are operands and C is an operator. 
 

Output
For each case, print the operation result. The result should be rounded to 2 decimal places If and only if it is not an integer.
 

Sample Input
4+ 1 2- 1 2* 1 2/ 1 2
 

Sample Output
3-120.50





解题思路:水。直接的就是简单的四则运算。不过要注意,最大的坑在于:当两数相除时,若能整除,则要输出整数,否则输出两位小数。




AC代码:

#include <iostream>#include <cstdio>using namespace std;int main(){//freopen("in.txt", "r", stdin);int n, a, b;char p[2];scanf("%d", &n);for(int i=0; i<n; i++){scanf("%s", p);scanf("%d%d", &a, &b);if(p[0] == '-') printf("%d\n", a-b);else if(p[0] == '+') printf("%d\n", a+b);else if(p[0] == '*') printf("%d\n", a*b);else{if(a%b) printf("%.2f\n", a*1.0/b);else printf("%d\n", a/b);}  }return 0;}



0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 红米2开机停在mi怎么办 红米手机无法开机怎么办 小米手机帐号密码忘了怎么办 小米手机忘记小米账号密码怎么办 小米4账号密码忘了怎么办 小米2a触屏失灵怎么办 红米note5拍照不清晰怎么办 红米手机太卡怎么办 红米3x忘记密码怎么办 红米手机太卡了怎么办 红米手机太卡怎么办? 红米3老是死机怎么办 红米3s经常死机怎么办 红米4a进水了怎么办 魅族耳机声音小怎么办 魅蓝note6声音小怎么办 魅蓝3s锁定怎么办 红米1密码忘了怎么办 小米手环升级失败怎么办 红米4忘记密码怎么办 红米1代忘记密码怎么办 红米3s忘记密码怎么办 小米3卡槽卡住了怎么办 红米4手机信号不好怎么办 红米note3信号差怎么办 红米note3没信号怎么办 红米3运行慢怎么办 红米手机运行慢怎么办 红米手机忘记解锁图案怎么办 小米手机解锁图案忘了怎么办 红米2内屏坏了怎么办 红米密码忘记了怎么办 红米pro玩王者卡怎么办 红米note4不支持计步怎么办 红米pro玩游戏卡怎么办 红米手机费电快怎么办 荣耀5c忘记密码怎么办 小米之家不退货怎么办 手机号绑定过多小米账户怎么办 耐克黑色鞋褪色怎么办 买广汽传祺7s新车有问题怎么办