HDOJ(HDU) 2143 box(简单的多次判断-用的卫条件)

简介: HDOJ(HDU) 2143 box(简单的多次判断-用的卫条件)

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!


题意:

给你3个数,判断其中2个数进行+-*/%运算后的结果是不是剩余的那个数。


注意几点:

1.数据类型要用long型,不然数据会溢出。

2.除法是真实的除法,是计算机的3/2=1.5;不是计算机的1;

3.求模判断不为0;

4.其他两个数是和本身不同的两个数,不包括本身。

import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            long a = sc.nextLong();
            long b = sc.nextLong();
            long c = sc.nextLong();
            //a+b=c,也就是c-b=a,c-a=b;
            if((a+b)==c||(b+c)==a||(a+c)==b){
                System.out.println("oh,lucky!");
                continue;
            }
            //这里用乘法判断除法好些。a*b=c也就是c/b=a.c/a=b(实际上)
            //因为这里的判断除法是:3/2=1.5的。计算机中的int,long进行除法:3/2=1;
            //如果我们写除法判断,还要判断结果是不是整数、
            if((a*b)==c||(a*c)==b||(b*c)==a){
                System.out.println("oh,lucky!");
                continue;
            }
            //不能对0取模
            if((b!=0&&(a%b==c||c%b==a))||(c!=0&&(a%c==b||b%c==a)||(a!=0&&(b%a==c||c%a==b)))){
                System.out.println("oh,lucky!");
                continue;
            }
            System.out.println("what a pity!");
        }
    }
}
目录
相关文章
|
2月前
|
C++
【PTA】​L1-050 倒数第N个字符串 ​ (C++)
【PTA】​L1-050 倒数第N个字符串 ​ (C++)
34 0
【PTA】​L1-050 倒数第N个字符串 ​ (C++)
|
6月前
poj 2362 hdoj 1518 Square(搜索)
不难了解,小棒子的长度越长,其灵活性越差。例如长度为5的一根棒子的组合方式要比5根长度为1的棒子的组合方式少,这就是灵活性的体现。
24 0
|
6月前
hdoj 1028/poj 2704 Pascal's Travels(记忆化搜索||dp)
有个小球,只能向右边或下边滚动,而且它下一步滚动的步数是它在当前点上的数字,如果是0表示进入一个死胡同。求它从左上角到右下角到路径数目。 注意, 题目给了提示了,要用64位的整数。
25 0
HDOJ(HDU) 2162 Add ‘em(求和)
HDOJ(HDU) 2162 Add ‘em(求和)
59 0
|
Java
HDOJ/HDU 1297 Children’s Queue(推导~大数)
HDOJ/HDU 1297 Children’s Queue(推导~大数)
109 0
HDOJ/HDU 1321 Reverse Text(倒序输出~)
HDOJ/HDU 1321 Reverse Text(倒序输出~)
77 0
HDOJ(HDU) 2088 Box of Bricks(平均值)
HDOJ(HDU) 2088 Box of Bricks(平均值)
66 0
HDOJ(HDU) 2088 Box of Bricks(平均值)
HDOJ 1397 Goldbach's Conjecture(快速筛选素数法)
HDOJ 1397 Goldbach's Conjecture(快速筛选素数法)
75 0
HDOJ(HDU) 2138 How many prime numbers(素数-快速筛选没用上、)
HDOJ(HDU) 2138 How many prime numbers(素数-快速筛选没用上、)
81 0
|
人工智能
HDOJ/HDU 2710 Max Factor(素数快速筛选~)
HDOJ/HDU 2710 Max Factor(素数快速筛选~)
80 0