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!");
        }
    }
}
目录
相关文章
|
机器学习/深度学习 人工智能 BI
The Great Hero(Codeforces Round #700 (Div. 2))模拟+贪心思想和排序
The Great Hero(Codeforces Round #700 (Div. 2))模拟+贪心思想和排序
60 0
|
人工智能 算法
Codeforces #737Div2A. A. Ezzat and Two Subsequences(模拟)
Codeforces #737Div2A. A. Ezzat and Two Subsequences(模拟)
47 0
Codeforces Round 859 (Div. 4)题解
Codeforces Round 859 (Div. 4)题解
100 0
|
人工智能 BI
Codeforces Round #805 (Div. 3) 题解
Codeforces Round #805 (Div. 3) 题解
Codeforces Round #805 (Div. 3) 题解
|
机器学习/深度学习 Windows
Codeforces Round #748 (Div. 3) F - Red-Black Number (记忆化搜索)
Codeforces Round #748 (Div. 3) F - Red-Black Number (记忆化搜索)
101 0
|
人工智能 索引
Codeforces Round #806 (Div. 4) 题解
Codeforces Round #806 (Div. 4) 题解
HDOJ(HDU) 2088 Box of Bricks(平均值)
HDOJ(HDU) 2088 Box of Bricks(平均值)
87 0
HDOJ(HDU) 2088 Box of Bricks(平均值)
HDOJ(HDU) 2162 Add ‘em(求和)
HDOJ(HDU) 2162 Add ‘em(求和)
72 0