题目1175:打牌

题目描述:

牌只有1到9,手里拿着已经排好序的牌a,对方出牌b,用程序判断手中牌是否能够压过对方出牌。 
规则:出牌牌型有5种  
[1]一张 如4 则5...9可压过
[2]两张 如44 则55,66,77,...,99可压过
[3]三张 如444 规则如[2]
[4]四张 如4444 规则如[2]
[5]五张 牌型只有12345 23456 34567 45678 56789五个,后面的比前面的均大。

输入:

输入有多组数据。
每组输入两个字符串(字符串大小不超过100)a,b。a字符串代表手中牌,b字符串代表处的牌。

输出:

压过输出YES 否则NO。

样例输入:
12233445566677
33
样例输出:
YES
import java.io.IOException;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Arrays;

class Main
{
	public static final boolean DEBUG = false;
	public static int[] cnt = new int[10];
	
	
	public static boolean check(int len, int ch)
	{
		if (len != 5) {
			for (int i = ch + 1; i < 10; i++) {
				if (cnt[i] >= len) return true;
			}
			
			return false;
		}
		
		for (int i = ch + 1; i < 10; i++) {
			if (cnt[i] >= 1 && (i + 1 < 10 && cnt[i + 1] >= 1) &&
				(i + 2 < 10 && cnt[i + 2] >= 1) && 
				(i + 3 < 10 && cnt[i + 3] >= 1) && 
				(i + 4 < 10 && cnt[i + 4] >= 1)) return true;
		}
		
		return false;
	}
	
	public static void solve(String s)
	{
		int len = s.length(); 
		int ch = s.charAt(0) - '0';
		
		if (check(len, ch)) System.out.println("YES");
		else System.out.println("NO");
	}
	
	public static void main(String[] args) throws IOException
	{
		Scanner cin;
		String s;
		
		if (DEBUG) {
			cin = new Scanner(new FileReader("d:\\OJ\\uva_in.txt"));
		} else {
			cin = new Scanner(new InputStreamReader(System.in));
		}
		
		while (cin.hasNext()) {
			s = cin.next();
			Arrays.fill(cnt, 0);
			
			int len = s.length();
			for (int i = 0; i < len; i++) {
				char ch = s.charAt(i);
				cnt[ch - '0']++;
			}
			
			s = cin.next();
			solve(s);
		}
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kgduu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值