HDOJ2143 box

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!");
			}
		}
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值