您的位置:首页 > 其它

Not so Mobile (针对递归输入的函数)

2015-07-22 14:45 405 查看
Before being an ubiquous communications gadget, a mobile was just a structure made of strings and wires suspending colourfull things. This kind of mobile is usually found hanging over cradles of small babies.

#include <iostream>
using namespace std;

bool solve(int &W)
{
int W1,W2,D1,D2;
cin>>W1>>D1>>W2>>D2;
bool b1=true,b2=true;
if(W1==0) b1=solve(W1);
if(W2==0) b2=solve(W2);
W=W1+W2;
return b1&&b2&&(W1*D1==W2*D2);
}

int main()
{
int T,W;
cin>>T;
while(T--)
{
if(solve(W)) cout<<"YES\n";
else         cout<<"NO\n";
if(T)        cout<<"\n";
}
return 0;
}


View Code

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: