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!
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
- HDU 1170 Balloon Comes!
- HDU 1170 ( Balloon Comes! )
- HDU 1170 Balloon Comes!
- HDU 1170 Balloon Comes!
- HDU 1170Balloon Comes!
- HDU 1170 Balloon Comes!
- HDU 1170 Balloon Comes!
- hdu 1170 Balloon Comes
- hdu-1170 Balloon Comes!
- HDU 1170 Balloon Comes!
- HDU 1170 Balloon Comes!
- hdu-oj 1170 Balloon Comes!
- hdu 1170 Balloon Comes!(模拟)
- HDU 1170 Balloon Comes!【水题】
- hdu 1170 Balloon Comes! 水的很 !!!!!!!!!
- hdu 1170 Balloon Comes!(水题)
- HDU 1170 Balloon Comes! 简单的四则运算
- 杭电 HDU 1170 Balloon Comes!
- 一键停止所有activity,退出程序
- href=#与href=javascriptvoid(0)的区别
- 视频监控ActiveX控件总结
- java学习笔记
- 用JS改变的元素CSS样式
- HDU 1170 Balloon Comes!
- There is no ‘Animation’ attached to the “Player” game object
- java中类的继承调用顺序例子
- 猫都能学会的Unity3D Shader入门指南(一)
- 第十周项目五:1000以内所有的完数
- ps命令显示用户名而不是uid
- Tomcat设置成NIO时,使用的线程池
- 【bzoj 3687】: 简单题
- 【POJ3660】Cow Contest Floyd传递闭包