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!");
        }
    }
}
时间: 2024-08-26 09:25:06

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

HDOJ(HDU) 2088 Box of Bricks(平均值)

Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds stacks of different height. "Look, I've built a wall!", he tells his older sister Alice. "Nah, you should make all stacks th

HDOJ/HDU 2568 前进(简单题)

Problem Description 轻松通过墓碑,进入古墓后,才发现里面别有洞天. 突然,Yifenfei发现自己周围是黑压压的一群蝙蝠,个个扇动翅膀正准备一起向他发起进攻! 形势十分危急! 好在此时的yifenfei已经不是以前那个经常被lemon抢走MM的菜鸟了!面对众多蝙蝠的嗜血狂攻,只见yifenfei使出轻灵的剑法,刷,刷,刷,瞬间搞定-- 现已知yifenfei使用了2招(剑招A和剑招B):剑招A,一招能杀死一半的蝙蝠.但是如果当前的蝙蝠数为奇数,那么就必须先出一招剑招B杀死其中

HDOJ(HDU) 1976 Software Version(简单判断)

Problem Description 相信大家一定有过在网上下载软件而碰到多个不同版本的情况. 一般来说,软件的版本号由三个部分组成,主版本号(Major Version Number),子版本号(Minor Version Number)和修订号(Revision_Number).当软件进行了重大的修改时,主版本号加一:当软件在原有基础上增加部分功能时,主版本号不变,子版本号加一:当软件仅仅修正了部分bug时,主版本号和子版本号都不变,修正号加一. 在我们比较软件的两个版本的新旧时,都是先比

HDOJ(HDU) 1491 Octorber 21st

Problem Description HDU's 50th birthday, on Octorber 21st, is coming. What an exciting day!! As a student of HDU, I always want to know how many days are there between today and Octorber 21st.So, write a problem and tell me the answer.Of course, the

HDOJ(HDU) 2109 Fighting for HDU(简单排序比较)

Problem Description 在上一回,我们让你猜测海东集团用地的形状,你猜对了吗?不管结果如何,都没关系,下面我继续向大家讲解海东集团的发展情况: 在最初的两年里,HDU发展非常迅速,综合各种ACM算法生成的老鼠药效果奇好,据说该药专对老鼠有效,如果被人误食了,没有任何副作用,甚至有传闻说还有健胃的效果,不过这倒没有得到临床验证.所以,公司的销量逐年递增,利润也是节节攀升,作为股东之一的公主负责财务,最近半年,她实在辛苦,多次因为点钞票造成双手抽筋而住院,现在在她面前你根本不要提到"

HDOJ/HDU 1029 Ignatius and the Princess IV(简单DP,排序)

此题无法用JavaAC,不相信的可以去HD1029题试下! Problem Description "OK, you are not too bad, em- But you can never pass the next test." feng5166 says. "I will tell you an odd number N, and then N integers. There will be a special integer among them, you hav

HDOJ/HDU 2537 8球胜负(水题.简单的判断)

Problem Description 8球是一种台球竞赛的规则.台面上有7个红球.7个黄球以及一个黑球,当然还有一个白球.对于本题,我们使用如下的简化规则:红.黄两名选手轮流用白球击打各自颜色的球,如果将该颜色的7个球全部打进,则这名选手可以打黑球,如果打进则算他胜.如果在打进自己颜色的所有球之前就把黑球打进,则算输.如果选手不慎打进了对手的球,入球依然有效. 现在给出打进的球(白球除外)的顺序,以及黑球由哪方打进,你的任务是判定哪方是胜者. 假设不会有一杆同时打进一颗黑球和其他彩球. Inp

HDOJ(HDU) 1994 利息计算(简单题目)

Problem Description 为自行解决学费,chx勤工俭学收入10000元以1年定期存入银行,年利率为3.7% .利率 按年计算,表示100元存1年的利息为3.7元.实际上有时提前有时推迟取,因此实际利息按天 计算,1年按365天计算,因此Q天的利息是 本金*3.7/100 *Q/365 存了100天后1年定期年利息提高到3.9%.如将存款提前全取出,再存1年定期.那么前面的 100天只能按活期利息1.7%计算. 100天的利息和本金:10000(1+1.7/100*100/365)

HDOJ(HDU) 2123 An easy problem(简单题...)

Problem Description In this problem you need to make a multiply table of N * N ,just like the sample out. The element in the ith row and jth column should be the product(乘积) of i and j. Input The first line of input is an integer C which indicate the