Not so Mobile(UVA 839)
网址如下:
Not so Mobile - UVA 839 - Virtual Judge (vjudge.net)
(第三方网站)
递归输入来模拟二叉树
可以边输入边判断
如果结果是NO,则这一组的数据有可能没读完,所以需要一个clear函数来把剩余输入吃掉
代码如下:
#include<cstdio>
void clear(void);
bool is_judge(int &W);
int main(void)
{
int tmp = 0, kase;
scanf("%d", &kase);
while(kase--)
{
if(is_judge(tmp))
printf("YES\n");
else
printf("NO\n");
if(kase){putchar('\n'); clear();}
}
return 0;
}
bool is_judge(int &W)
{
int WL, DL, WR, DR;
scanf("%d%d%d%d", &WL, &DL, &WR, &DR);
if(!WL){if(!is_judge(WL)) return false;}
if(!WR){if(!is_judge(WR)) return false;}
if(!W) W = WL + WR;
if(WL * DL == WR * DR) return true;
else return false;
}
void clear(void)
{
char fc{}, bc{};
while(fc != '\n' || bc != '\n')
{
fc = bc;
bc = getchar();
}
}