HDOJ2143 box
来源:互联网 发布:王思聪双性恋 知乎 编辑:程序博客网 时间:2024/06/07 05:52
box
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 9731 Accepted Submission(s): 2155
Problem Description
One day, winnie received a box and a letter. In the letter, there are three integers and five operations(+,-,*,/,%). If one of the three integers can be calculated by the other two integers using any operations only once.. He can open that mysterious box. Or that box will never be open.
Input
The input contains several test cases.Each test case consists of three non-negative integers.
Output
If winnie can open that box.print "oh,lucky!".else print "what a pity!"
Sample Input
1 2 3
Sample Output
oh,lucky!
简单题,十分简单。
加和减是相对应的,乘和除是相对的,另外取余的时候a%b,b不能是0,需要防护。
import java.util.Scanner;public class Main{private static Scanner scanner;public static void main(String[] args) {scanner = new Scanner(System.in);while (scanner.hasNext()) {//没讲多大,使用longlong a = scanner.nextLong();long b = scanner.nextLong();long c = scanner.nextLong();boolean boo = false;// 加和减相对,乘和除相对if (a + b == c || b + c == a || a + c == b) {boo = true;} else if (a * b == c || b * c == a || a * c == b) {boo = true;}// 防范//对于:a%0出现的错误是java.lang.ArithmeticException: / by zeroelse if (a != 0 && (b % a == c || c % a == b)) {boo = true;} else if (b != 0 && (a % b == c || c % b == a)) {boo = true;} else if (c != 0 && (b % c == a || a % c == b)) {boo = true;}if (boo) {System.out.println("oh,lucky!");} else {System.out.println("what a pity!");}}}}
阅读全文
0 0
- HDOJ2143 box
- box
- Box
- box
- Box
- Box
- Box
- Box
- box-sizing:border-box
- box-sizing:border-box;
- box-sizing:border-box
- box-sizing:border-box;
- css3 box-orient box-pack box-align
- combo box
- class Box
- Box容器
- Combo box
- Box.net
- arm架构寄存器介绍
- netty LengthFieldBasedFrameDecoder 使用实例
- asp.net Web项目中使用Log4Net进行错误日志记录
- sphinx使用整理文档
- 算法训练 数位分离
- HDOJ2143 box
- Data Analytics for Beginners:第三节
- c++
- js经典面试问题:如何让for循环中的setTimeout()函数像预想中一样工作?
- java的list集合的逆序与复制
- I am back !
- 西门子S7-200 CODE段
- 修改Material Design库的版本导致TabLayout无法使用的问题解决
- 第四章 朴素贝叶斯