杭电之BOX

                                          box

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5020    Accepted Submission(s): 968


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!
这道题英语听懂就很好理解,但是,主要是看到五个符号,还有三个字,不知道怎么分配。要是把循环写在mian()函数里,会让代码看的比较乱。可以写外部函数,因为加法、乘法成立,减法和除法就不用写了。外部函数,返回bool型,判断对错。main()函数里用if()判断,虽然好多的种类,但是用“||”只要有一个true就可以得到结果了。ps:因为数据比较大,所以普通的int不行,定义————int64可以满足条件。还有一个,就是每次用c输入都要判断EOF,要不然,程序会超时。
#include<iostream>
#include<cstdio>
using namespace std;
int jia(__int64 x1,__int64 x2,__int64 x3)
{
	bool f=false;
	if(x1+x2==x3)
		f=true;
	return f;
}
int cheng(__int64 x1,__int64 x2,__int64 x3)
{
	bool f=false;
	if(x1*x2==x3)
		f=true;
	return f;
}
int yu(__int64 x1,__int64 x2,__int64 x3)
{
	bool f=false;
	if(x2!=0)
	{
	if(x1%x2==x3)
		f=true;
	}
	return f;
}
int main()
{
	__int64 a,b,c;
	while(scanf("%I64d%I64d%I64d",&a,&b,&c)!=EOF)
	{
		if(jia(a,b,c)||jia(a,c,b)||jia(b,c,a)||cheng(a,b,c)||cheng(a,c,b)||cheng(c,b,a)||yu(a,b,c)||yu(a,c,b)||yu(b,c,a)||yu(b,a,c)||yu(c,a,b)||yu(c,b,a))
			cout<<"oh,lucky!"<<endl;
		else
			cout<<"what a pity!"<<endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值