首页 > 其他分享 >HDOJ2143 box

HDOJ2143 box

时间:2023-02-20 10:35:59浏览次数:28  
标签:box integers scanner else boo HDOJ2143 true


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()) {
//没讲多大,使用long
long 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 zero
else 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!");
}
}
}
}



标签:box,integers,scanner,else,boo,HDOJ2143,true
From: https://blog.51cto.com/u_15741949/6067726

相关文章