题目1175:打牌
来源:互联网 发布:ubuntu cuda test 编辑:程序博客网 时间:2024/05/15 19:43
- 题目描述:
牌只有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。
- 样例输入:
1223344556667733
- 样例输出:
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);}}}
0 0
- 题目1175:打牌
- 题目1175:打牌
- 题目1175:打牌
- 题目1175:打牌
- 题目1175:打牌
- 题目1175:打牌
- 九度题目1175:打牌
- 九度OJ 题目1175:打牌
- 北邮机试 九度 题目1175:打牌
- 【九度OJ】题目1175:打牌 解题报告
- 九度oj 题目1175:打牌--string类的find方法
- 九度OJ-题目1175:打牌-10网研上机C
- 打牌
- 打牌
- 打牌
- 打牌
- 线上编程挑战5月份月赛题目:打牌
- CSDN线上编程挑战5月份月赛题目:打牌
- 直接调用带参数方法创建新线程及 wpf中跨线程访问控件
- WIKIOI 1142奖学金
- jrebel(破解版)+eclipse +jetty/tomcat 配置,实现热部署
- 有你就是温暖
- 对嵌入式的学习问题
- 题目1175:打牌
- 使用Redis的脚本功能实现Redis中数据简单查询
- android中 分享的写法
- 利用Bat访问电脑共享 ,不再重复输入 密码
- 不规则窗体的应用增加软件的吸引力
- 23种设计模式(8):观察者模式
- 分辨数字枪与模拟枪几点优劣
- C++ task.h
- Linux多线程编程之基础函数