二十四点

package ncu.edu.ccf;

import java.util.Scanner;

public class ErShiSiDian {
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int n = sc.nextInt();
		int num[] = new int[7];//****
		for(int i = 0; i < n; i++) {
			String s = sc.next();//读入一行数据,读入字符串
			for(int m = 0; m < 7; m++) {
				num[m] = s.charAt(m);//检索字符串s中m位置的字符
			}
			for(int j = 0; j <= 4; j += 2) {
				if(num[j+1] == 'x' ||num[j+1] == '/') {
					num[j+2] = '0' + way(num[j], num[j+2], num[j+1]);
					num[j] = '0';
					num[j + 1] = j==0?'+':num[j-1];
				}
			}
			for (int k = 0; k <= 4; k += 2) {
				if (num[k + 1] == '+' || num[k + 1] == '-') {
					num[k + 2] = '0' + way(num[k], num[k + 2], num[k + 1]);
				}
			}
			if (num[6] == '0' + 24) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}		
	}
		
	static int way(int a, int b, int operator) {	
		int a1 = a - '0';//将char类型转换成int类型 
		int b1 = b - '0';
		switch (operator) {
		case '+':
			return a1 + b1;
		case '-':
			return a1 - b1;
		case 'x':
			return a1 * b1;
		case '/':
			return a1 / b1;
		}
		return 0;
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值