Title Description :
Qingyise is one of the varieties of mahjong , The sum of a suit's ordinal cards .
number 1-9, Each number has a maximum of 4 Cards
We don't consider the specific decor , We just look at the combination of numbers .
Carving : Three identical cards ; as : 111, 222, 333, ... 999
Shunzi : Three consecutive cards ; as : 123, 234, 345, ... 789
Pair : Two identical cards ; as : 11, 22, 33, ... 99
Need to implement a program , Judge the given card , Is it possible to draw cards ( Hu Pai ).
Licensing requirements :
- Mahjong card number can only be 2, 5, 8, 11, 14
- Given cards can be combined into , except 1 Except for a couple, all the others are Kezi or shunzi
give an example : - "11" -> "11", 1 Pair , You can draw cards
- "11122233" -> "111"+"222"+"33", 2 Carving ,1 Pair , sure
- "11223344567" -> "11"+"234"+"234"+"567", 1 Pair ,3 Shunzi , sure
-> "123"+"123"+"44"+"567", Another combination , it's fine too
Input description :
legitimate C character string , Contains only '1'-'9', And they've been sorted from small to large ; String length is not more than 15. The same number appears at most 4 second , In accordance with the actual situation .
Output description :
C character string ,"yes" perhaps "no"
Examples 1
input
2244
output
24 // Here is the original appearance of the test question , Should output no

thinking :

The key point is to understand the order of playing cards , The code implementation adopts the idea of combination classification , I haven't thought of a technical way yet

code :
import java.util.Scanner; import java.util.regex.Pattern; /** * Created by
1443754157@qq.com since 2018 year 9 month 12 day afternoon 11:23:21. */ public class Mahjong { static
final String duizi =
"[1][1]|[2][2]|[3][3]|[4][4]|[5][5]|[6][6]|[7][7]|[8][8]|[9][9]"; static final
String shunzi =
"[9][8][7]|[8][7][6]|[7][6][5]|[6][5][4]|[5][4][3]|[4][3][2]|[3][2][1]"; static
final String kezi =
"[1]{3}|[2]{3}|[3]{3}|[4]{3}|[5]{3}|[6]{3}|[7]{3}|[8]{3}|[9]{3}"; public static
void main(String[] args) { Mahjong mahjong = new Mahjong(); Scanner scanner =
new Scanner(System.in); while (scanner.hasNextLine()) { String input =
scanner.nextLine(); int len = input.length(); if (len > 15 || len < 1 ||
!input.matches("^[1-9]{1,15}$")) { System.out.println(" Input data error ,no"); continue; }
// The input data length of the card can only be drawn 2/5/8/11/14 if (len == 2 || len == 5 || len == 8 || len == 11
|| len == 14) { String reverse = new StringBuilder(input).reverse().toString();
System.out.println(mahjong.judge(reverse) ? "yes" : "no"); } else {
System.out.println(" The length of input data cannot be Hu ,no"); } } scanner.close(); } /** *
Judge whether it is possible to draw cards , The input data has been verified and reversed * * @param data * @return */ public boolean judge(String
data) { System.out.println(data); if (data.length() == 0) { return true; } else
{ // Determine whether the input has pairs / Carving / Shunzi , Remove if any boolean hasDuizi = hasDuizi(data); boolean hasShunzi
= hasShunzi(data); boolean hasKezi = hasKezi(data); if (hasDuizi) { // There are pairs if
(hasShunzi) { // There is shunzi if (hasKezi) { // There is an inscription ---> All three String middle =
data.replaceAll(shunzi, ""); return judge(middle); } else { // There is no inscription ---> There are only shunzi and shunzi
String middle = data.replaceAll(duizi, ""); return judge(middle); } } else { //
There is no shunzi // 1. There is an inscription ---> There are only couplets and engravings eg:45556/22266 2. There is no inscription ---> There are only pairs String middle =
data.replaceAll(duizi, ""); return judge(middle); } } else { // There is no pair if
(hasShunzi) { // There is shunzi // 1. There is an inscription ---> There are only shunzi and Kezi 2. There is no inscription ---> Only shunzi String middle =
data.replaceAll(shunzi, ""); return judge(middle); } else { // There is no shunzi if
(hasKezi) { // There is an inscription ---> It's only carved String middle = data.replaceAll(kezi, ""); return
judge(middle); } else { // There is no inscription ---> None of the three return false; } } } } } public boolean
hasDuizi(String data) { return Pattern.compile(duizi).matcher(data).find(); }
public boolean hasShunzi(String data) { return
Pattern.compile(shunzi).matcher(data).find(); } public boolean hasKezi(String
data) { return Pattern.compile(kezi).matcher(data).find(); } }
 

Technology
©2019-2020 Toolsou All rights reserved,
JQ get request Splicing url parameter ( query criteria )PostgreSQL: Nine . Indexes Forbes China Auto rich list : He xiaopengdi 11 Li Xiangdi 14 Li Bindi 1511-5 Output string at specified position golang One line of code converts the slice into a semicolon separated string ( Essence 2020 year 6 month 3 Daily update ) TypeScript Detailed explanation of Chinese interface LED Scrolling text SpringMVC Frame in controller Layer gets the property value of the custom configuration file Go language Array initialization and basic operations use mt-range The effect of changing a number with the sliding bar is realized