hdu 2143 box

box

                                                                     Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)


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!
 
这道题我一开始是把能出现的情况列举出来,但是结果是发生了除0错误。后来仔细想了一下,减法是加法的逆运算,除法是乘法的逆运算算,如果判断相乘,就不会出现除0的错误,而且我们判断加法以后,就不用再判断减法,判断乘法以后就不用判断除法。还有要注意的是,a%b时b不能等于0, 题目中的'/'是 “除”而不是“取整”,要小心,这个地方让我wa了好几次。
代码如下:
#include<stdio.h>
int main()
{

    __int64 a,b,c;
    while(scanf("%I64d%I64d%I64d",&a,&b,&c)!=EOF)
    {
        int p=0;
        if(a+b==c||a+c==b||b+c==a||a*b==c||a*c==b||b*c==a)
           p=1;
        if(a!=0)
        {
            if(b%a==c||c%a==b)
              p=1;
        }
        if(b!=0)
        {
            if(a%b==c||c%b==a)
              p=1;
        }
        if(c!=0)
        {
            if(a%c==b||b%c==a)
              p=1;
        }
        if(p)
          printf("oh,lucky!\n");
        else
          printf("what a pity!\n");
    }
    return 0;
}
有一个迷惑的地方:为什么a,b,c定义成64位整数能AC,定义成int型过不了?
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值