您的位置:首页 > 其它

UVA - 839 Not so Mobile

2014-10-13 00:03 381 查看
题目大意:求两边天平是否相等

解题思路:用递归,因为如果天平上为零的话就要继续读,在用一个全局变量记录是否平衡,这样就不怕在递归的过程中导致不平衡发生而被跳过

#include<cstdio>
int mark ;

int judge() {
	int num[4];
	for(int i = 0; i < 4; i++)  {
		scanf("%d", &(num[i]));	
//		printf("%d\t",num[i]);
	}
//	printf("\n");
	if(num[0] == 0)
		num[0] = judge();
	if(num[2] == 0)
		num[2] = judge();
	if(num[0] * num[1] != num[2] * num[3])
		mark = 0;
	return num[0] + num[2];	
}

int main() {
	int test;
	scanf("%d", &test);
	while(test--) {
		mark = 1;
		int temp = judge();
		if(mark == 0)
			printf("NO\n");
		else
			printf("YES\n");
		if(test)
			printf("\n");	
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: