zoukankan      html  css  js  c++  java
  • 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!");
            }
        }
    }
    
  • 相关阅读:
    STM32 printf 方法重定向到串口UART
    STM32F401CCU6与MFRC522接线及读取示例
    Keil MDK5 STM32F401CCU6开发环境配置
    Keil MDK5 STM32F103C8T6开发环境配置
    RFID EPC Class1 Gen2电子标签笔记
    Ubuntu20.04下的ESP8266环境
    Centos7使用memtester测试内存
    内核5.4以上, Realtek 8111网卡初始化失败
    Centos7的KVM安装配置详解
    Python抓取网页例子
  • 原文地址:https://www.cnblogs.com/webmen/p/5739225.html
Copyright © 2011-2022 走看看