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!");
            }
        }
    }
    
  • 相关阅读:
    Sql Server 收缩日志文件原理及always on 下的实践
    SQL Agent服务无法启动如何破
    Sql Server Always On 读写分离配置方法
    SQL SERVER 9003错误解决方法 只适用于SQL2000
    SQL Server 数据库分离与附加
    SQL SERVER 的模糊查询 LIKE
    sqlserver 时间格式函数详细
    浅谈SQL Server中的三种物理连接操作
    谈一谈SQL Server中的执行计划缓存(下)
    asp.net获取当前系统的时间
  • 原文地址:https://www.cnblogs.com/webmen/p/5739225.html
Copyright © 2011-2022 走看看