ACM HDU p1170 Balloon Comes!
来源:互联网 发布:战支援部队网络系统部 编辑:程序博客网 时间:2024/06/05 10:08
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
这里需要注意的是小数点的取舍 System.out.printf("%.2f",(float)x/y);
package HDU;import java.util.Scanner;public class P1170 {public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); while(n-->0){ String a=sc.next(); char b=a.charAt(0); int x= sc.nextInt(); int y=sc.nextInt(); int sum=0; if(b=='+'){ sum=x+y; System.out.println(sum); } if(b=='-'){ sum=x-y; System.out.println(sum); } if(b=='*'){ sum=x*y; System.out.println(sum); } if(b=='/'){ if(x%y==0){ System.out.println(x/y); }//这里注意,看清题目意思 else{ System.out.printf("%.2f",(float)x/y); System.out.println(); } } }}}
0 0
- ACM HDU p1170 Balloon Comes!
- HDU 1170 Balloon Comes!
- HDU 1170 ( Balloon Comes! )
- HDU 1170 Balloon Comes!
- hdu-Balloon Comes!
- HDU 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!
- 杭电 acm Balloon Comes!
- hdu-oj 1170 Balloon Comes!
- [HDU]1.2.3 Balloon Comes!
- hdu 1170 Balloon Comes!(模拟)
- 行为模式总结
- mount挂载失败。 mount failed reason given by server permission denied
- Android混淆
- hdu 3652 数位DP+dfs记忆化搜所
- Altium Designed 快捷键
- ACM HDU p1170 Balloon Comes!
- C++ const的使用
- 单点CAS搭建服务端+客户端
- 通过javascript获取URL中的参数
- 密码验证合格程序
- [HDU 3966] Aragorn's Story 树链剖分
- Code Forces 547 C. Mike and Foam(素因子分解+容斥)
- 将页脚固定在页面底部
- Linux平台上SQLite数据库教程(一)——终端使用篇