您的位置:首页 > 其它

uva 839 (Not so mobile)天平 ---递归输入

2017-03-07 11:24 405 查看
java的写法

import java.util.Scanner;

public class Main {
static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
int T = scan.nextInt();
while(T--!=0){
if(solve(new M(0))){
System.out.println("YES");
}else{
System.out.println("NO");
}
if(T!=0)System.out.println();
}
}
private static boolean solve(M w) {
M wl = new M(scan.nextInt());
M dl = new M(scan.nextInt());
M wr = new M(scan.nextInt());
M dr = new M(scan.nextInt());
boolean b1 = true,b2 = true;
if(wl.value==0)b1 = solve(wl);
if(wr.value==0)b2 = solve(wr);
w.value = wl.value+wr.value;
return b1&&b2&&wl.value*dl.value==wr.value*dr.value;
}

static class M{
public int value;
public M(int value){
this.value = value;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: