Language: C++



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
 * <pre>
 *AOJ Rummy?????????????????????????????????????????????????????°
 * </pre>
 *
 * @author ??????
 * @category AOJRummy
 * @version 1.8_45
 * @since 1.8_45
 */
public class Main{

	public static void main(String[] args) throws NumberFormatException, IOException {

		// ?????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		// ?????????????´???´???
		ArrayList<Integer> answer = new ArrayList<Integer>();

		// ?????????????????°
		int cardhuda = 9;

		// 1??????????????????set?????°??????????????°
		int set = Integer.parseInt(br.readLine());

		// for????????? set????????°?????????
		for (int cnt1 = 0; cnt1 < set; cnt1++) {
			/**
			 * @param cardArr
			 *            ????´???´???
			 * @param tmpNum
			 *            ??°???????????±
			 * @param tmpColor
			 *            ???????????±
			 */
			ArrayList<UTRummyCard> cardArr = new ArrayList<UTRummyCard>();

			// ??????????????°??????????????¨????????????
			String tmpNum = br.readLine();
			// ??????????????????????????¨????????????
			String tmpColor = br.readLine();

			/**
			 * ?????°???????§£ ??°??????????´?
			 *
			 * @param transNum
			 *            ??°???????????±
			 * @param transColor
			 *            ???????????±
			 */
			String[] transNum = tmpNum.split(" ");
			String[] transColor = tmpColor.split(" ");

			// ?????????????????°?????????
			for (int cnt2 = 0; cnt2 < cardhuda; cnt2++) {
				boolean tool = false;
				// ????´??????????????????????????????????????????????
				// ????¨?????????????????????\
				cardArr.add(new UTRummyCard(Integer.parseInt(transNum[cnt2]), transColor[cnt2], tool));
			}

			/**
			 * ???????????¶??????????????°??? ????????????????????°0
			 *
			 * @param result
			 *            ?????????????????????????´???´???
			 */
			int result = utRummy(cardArr);
			// ?????????????´?
			answer.add(result);
		}
		// ???????????????
		outputAnswer(answer);
	}// ?????????????????????????????????

	/**
	 * ????????????
	 *
	 * @param answer
	 *            ?????????????´???´???
	 */
	private static void outputAnswer(ArrayList<Integer> answer) {

		// for????????? ??????????????????????????????
		for (int cnt = 0; cnt < answer.size(); cnt++) {
			// ???????????????
			System.out.println(answer.get(cnt));
		}
	}// outputAnswer????????????????????????

	/**
	 * ????????????????????´??? ??????????¨?
	 *
	 * @return result ??????????????????????????????
	 */
	private static int utRummy(ArrayList<UTRummyCard> cardArr) {

		// ?????????0???????????????
		int result = 0;

		// ????????????????????°???????????????
		cardNumSort(cardArr);
		// ?????????????????????????????????
		cardColorSort(cardArr);

		// ?????£?¶?
		serialCard(cardArr);

		// ????????°?????????
		sameCard(cardArr);

		int toolcnt = 0;
		for (int cnt = 0; cnt < cardArr.size(); cnt++) {
			if (cardArr.get(cnt).isUse() == false)
				toolcnt++;
		}
		return result = toolcnt == 0 ? 1 : 0;

	}// utRummy????????????????????????

	private static void sameCard(ArrayList<UTRummyCard> cardArr) {

		for (int cnt1 = 0; cnt1 < cardArr.size() - 2; cnt1++) {
			for (int cnt2 = cnt1 + 1; cnt2 < cardArr.size() - 1; cnt2++) {
				for (int cnt3 = cnt2 + 1; cnt3 < cardArr.size(); cnt3++) {
					// (1)?????????????????????????????????
					if (cardArr.get(cnt1).getFrontnumber() == cardArr.get(cnt2).getFrontnumber()
							&& cardArr.get(cnt2).getFrontnumber() == cardArr.get(cnt3).getFrontnumber()) {
						// (2)????????°????????????????????????
						if (cardArr.get(cnt1).getRearColor().equals(cardArr.get(cnt2).getRearColor())
								&& cardArr.get(cnt2).getRearColor().equals(cardArr.get(cnt3).getRearColor())) {
							// (3)????¨????????????????
							if (cardArr.get(cnt1).isUse() == false && cardArr.get(cnt2).isUse() == false
									&& cardArr.get(cnt3).isUse() == false) {

								cardArr.get(cnt1).setUse(true);
								cardArr.get(cnt2).setUse(true);
								cardArr.get(cnt3).setUse(true);
							}
						}
					}
				}
			}
		}
	}

	private static void serialCard(ArrayList<UTRummyCard> cardArr) {

		for (int cnt1 = 0; cnt1 < cardArr.size() - 2; cnt1++) {
			for (int cnt2 = cnt1 + 1; cnt2 < cardArr.size() - 1; cnt2++) {
				for (int cnt3 = cnt2 + 1; cnt3 < cardArr.size(); cnt3++) {
					// (1)?????????????????????????????????
					if (cardArr.get(cnt1).getRearColor().equals(cardArr.get(cnt2).getRearColor())
							&& cardArr.get(cnt2).getRearColor().equals(cardArr.get(cnt3).getRearColor())) {
						// (2)3??£?¶??????°????????????
						if (cardArr.get(cnt1).getFrontnumber() == cardArr.get(cnt2).getFrontnumber() - 1
								&& cardArr.get(cnt1).getFrontnumber() == cardArr.get(cnt3).getFrontnumber() - 2) {
							// (3)????¨????????????????
							if (cardArr.get(cnt1).isUse() == false && cardArr.get(cnt2).isUse() == false
									&& cardArr.get(cnt3).isUse() == false) {

								cardArr.get(cnt1).setUse(true);
								cardArr.get(cnt2).setUse(true);
								cardArr.get(cnt3).setUse(true);
							}
						}
					}
				}
			}
		}
	}

	/**
	 * ??????????????´???
	 *
	 * @param cardArr
	 *            ??´???????±????????????????
	 */
	private static void cardColorSort(ArrayList<UTRummyCard> cardArr) {

		for (int cnt1 = 0; cnt1 < cardArr.size() - 1; cnt1++) {
			for (int cnt2 = 0; cnt2 < cardArr.size() - 1 - cnt1; cnt2++) {
				if (cardArr.get(cnt2).getRearColor().charAt(0) < cardArr.get(cnt2 + 1).getRearColor().charAt(0)) {
					// ?????????????????????????????°
					UTRummyCard tmp = cardArr.get(cnt2);
					cardArr.set(cnt2, cardArr.get(cnt2 + 1));
					cardArr.set(cnt2 + 1, tmp);
				}
			}
		}
	}// cardColorSort????????????????????????

	/**
	 * ??????????????´???
	 *
	 * @param cardArr
	 *            ??´???????±????????????????
	 */
	private static void cardNumSort(ArrayList<UTRummyCard> cardArr) {
		for (int cnt1 = 0; cnt1 < cardArr.size() - 1; cnt1++) {
			for (int cnt2 = 0; cnt2 < cardArr.size() - 1 - cnt1; cnt2++) {
				if (cardArr.get(cnt2).getFrontnumber() > cardArr.get(cnt2 + 1).getFrontnumber()) {
					// ?????????????????????????????°
					UTRummyCard tmp = cardArr.get(cnt2);
					cardArr.set(cnt2, cardArr.get(cnt2 + 1));
					cardArr.set(cnt2 + 1, tmp);
				}
			}
		}
	}// cardSort????????????????????????

}// Rummy4?????????????????????

/**
 * ?????????Card
 *
 * @author ?????????????????§???
 */
class UTRummyCard {

	/**
	 * int ??????????????°????????\????????±????????\???
	 */
	private int frontnumber = 0;

	/**
	 * String ????????????????????\????????±????????\???
	 */
	private String rearColor = "";

	/**
	 * ????????????????¨??????????
	 */
	private boolean isUse = false;

	public int getFrontnumber() {
		return frontnumber;
	}

	public void setFrontnumber(int frontnumber) {
		this.frontnumber = frontnumber;
	}

	public String getRearColor() {
		return rearColor;
	}

	public void setRearColor(String rearColor) {
		this.rearColor = rearColor;
	}

	public UTRummyCard() {

	}

	public UTRummyCard(String white) {
		this.rearColor = white;
	}

	public boolean isUse() {
		return isUse;
	}

	public void setUse(boolean isUse) {
		this.isUse = isUse;
	}

	/**
	 * ????????????????????????????????????????????????????????°??¨??????int,String???
	 *
	 * @param num
	 *            ???????????????????????????????????°???
	 * @param color
	 *            ????????????????????????????????????
	 */
	public UTRummyCard(int num, String color, boolean tool) {
		frontnumber = num;
		rearColor = color;
		isUse = tool;
	}
}// UTRummyCard?????????????????????

Compiler output:
a.cc:3:1: error: 'import' does not name a type
    3 | import java.io.BufferedReader;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import java.io.IOException;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import java.io.InputStreamReader;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:1: error: 'import' does not name a type
    6 | import java.util.ArrayList;
      | ^~~~~~
a.cc:6:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:18:1: error: expected unqualified-id before 'public'
   18 | public class Main{
      | ^~~~~~
a.cc:232:16: error: expected ':' before 'int'
  232 |         private int frontnumber = 0;
      |                ^~~~
      |                :
a.cc:237:16: error: expected ':' before 'String'
  237 |         private String rearColor = "";
      |                ^~~~~~~
      |                :
a.cc:237:17: error: 'String' does not name a type
  237 |         private String rearColor = "";
      |                 ^~~~~~
a.cc:242:16: error: expected ':' before 'boolean'
  242 |         private boolean isUse = false;
      |                ^~~~~~~~
      |                :
a.cc:242:17: error: 'boolean' does not name a type; did you mean 'bool'?
  242 |         private boolean isUse = false;
      |                 ^~~~~~~
      |                 bool
a.cc:244:15: error: expected ':' before 'int'
  244 |         public int getFrontnumber() {
      |               ^~~~
      |               :
a.cc:248:15: error: expected ':' before 'void'
  248 |         public void setFrontnumber(int frontnumber) {
      |               ^~~~~
      |               :
a.cc:252:15: error: expected ':' before 'String'
  252 |         public String getRearColor() {
      |               ^~~~~~~
      |               :
a.cc:252:16: error: 'String' does not name a type
  252 |         public String getRearColor() {
      |                ^~~~~~
a.cc:256:15: error: expected ':' before 'void'
  256 |         public void setRearColor(String rearColor) {
      |               ^~~~~
      |               :
a.cc:256:34: error: 'String' has not been declared
  256 |         public void setRearColor(String rearColor) {
      |                                  ^~~~~~
a.cc:260:15: error: expected ':' before 'UTRummyCard'
  260 |         public UTRummyCard() {
      |               ^~~~~~~~~~~~
      |               :
a.cc:264:15: error: expected ':' before 'UTRummyCard'
  264 |         public UTRummyCard(String white) {
      |               ^~~~~~~~~~~~
      |               :
a.cc:264:34: error: expected ')' before 'white'
  264 |         public UTRummyCard(String white) {
      |                           ~      ^~~~~~
      |                                  )
a.cc:268:15: error: expected ':' before 'boolean'
  268 |         public boolean isUse() {
      |               ^~~~~~~~
      |               :
a.cc:268:16: error: 'boolean' does not name a type; did you mean 'bool'?
  268 |         public boolean isUse() {
      |                ^~~~~~~
      |                bool
a.cc:272:15: error: expected ':' before 'void'
  272 |         public void setUse(boolean isUse) {
      |               ^~~~~
      |               :
a.cc:272:28: error: 'boolean' has not been declared
  272 |         public void setUse(boolean isUse) {
      |                            ^~~~~~~
a.cc:284:15: error: expected ':' before 'UTRummyCard'
  284 |         public UTRummyCard(int num, String color, boolean tool) {
      |               ^~~~~~~~~~~~
      |               :
a.cc:284:37: error: 'String' has not been declared
  284 |         public UTRummyCard(int num, String color, boolean tool) {
      |                                     ^~~~~~
a.cc:284:51: error: 'boolean' has not been declared
  284 |         public UTRummyCard(int num, String color, boolean tool) {
      |                                                   ^~~~~~~
a.cc:289:2: error: expected ';' after class definition
  289 | }// UTRummyCard?????????????????????
      |  ^
      |  ;
a.cc: In member function 'void UTRummyCard::setFrontnumber(int)':
a.cc:249:22: error: request for member 'frontnumber' in '(UTRummyCard*)this', which is of pointer type 'UTRummyCard*' (maybe you meant to use '->' ?)
  249 |                 this.frontnumber = frontnumber;
      |                      ^~~~~~~~~~~
a.cc: In member function 'void UTRummyCard::setRearColor(int)':
a.cc:257:22: error: request for member 'rearColor' in '(UTRummyCard*)this', which is of pointer type 'UTRummyCard*' (maybe you meant to use '->' ?)
  257 |                 this.rearColor = rearColor;
      |                      ^~~~~~~~~
a.cc: In member function 'void UTRummyCard::setUse(int)':
a.cc:273:22: error: request for member 'isUse' in '(UTRummyCard*)this', which is of pointer type 'UTRummyCard*' (maybe you meant to use '->' ?)
  273 |                 this.isUse = isUse;
      |                      ^~~~~
a.cc: In constructor 'UTRummyCard::UTRummyCard(int, int, int)':
a.cc:286:17: error: 'rearColor' was not declared in this scope; did you mean 'setRearColor'?
  286 |                 rearColor = color;
      |                 ^~~~~~~~~
      |                 setRearColor
a.cc:287:17: error: 'isUse' was not declared in this scope
  287 |                 isUse = tool;
      |                 ^~~~~