# csp的24点问题

0

【题目背景】

【题目描述】

【输入格式】

【输出格式】

import java.util.Scanner;

public class Main {

``````public static int compute(int a,int b,char c) {
switch (c) {
case '/':return a/b;
case 'x':return a*b;
case '-':return a-b;
case '+':return a+b;
default:return -1000;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
char[][] ari = new char[n][];
for(int i=0;i<n;i++)
ari[i]=sc.next().toCharArray();
sc.close();
int a,b,c,d,result;
for(int i=0;i<n;i++) {
result = 0;
a = Integer.parseInt(String.valueOf(ari[i][0]));
b = Integer.parseInt(String.valueOf(ari[i][2]));
c = Integer.parseInt(String.valueOf(ari[i][4]));
d = Integer.parseInt(String.valueOf(ari[i][6]));
if(ari[i][1]=='x'||ari[i][1]=='/') {
result=compute(a, b, ari[i][1]);
if(ari[i][3]=='x'||ari[i][3]=='/') {
result=compute(result, c, ari[i][3]);
result=compute(result, d, ari[i][5]);
}else {
result=compute(result, compute(c, d, ari[i][5]), ari[i][3]);
}
}else {
if(ari[i][3]=='x'||ari[i][3]=='/') {
result=compute(b, c, ari[i][3]);
result=compute(result, d, ari[i][5]);
result=compute(a, result, ari[i][1]);
}else {
result=compute(c, d, ari[i][5]);
result=compute(b, result, ari[i][3]);
result=compute(a, result, ari[i][1]);
}
}
if(result==24)
System.out.println("Yes");
else
System.out.println("No");
}

}``````

}

DreamGod | 初学一级 | 园豆：152

0

Noble_S | 菜鸟二级 |园豆：254 | 2019-09-09 16:07

DreamGod | 园豆：152 (初学一级) | 2019-09-10 14:48

0

您需要登录以后才能回答，未注册用户请先注册