SWEA_D4_6959_이상한 나라의 덧셈게임

SWEA

6959. 이상한 나라의 덧셈게임

문제를 잘 읽고 신중하게 생각해보자 대충하지 말자 ㅠ_ㅠ 조건 잘 보자……….

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Solution  {
	static int T, count;
	static StringBuilder sb;

	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		T = Integer.parseInt(in.readLine().trim());
		for (int test_case = 1; test_case <= T; test_case++) {
			count = 0;
			getResult(in.readLine().toCharArray());
			System.out.println("#" + test_case + " " + (count % 2 == 1 ? 'A' : 'B'));
		}
	}

	private static void getResult(char[] num) {
		sb = new StringBuilder();
		int i = 0, size = num.length;
		if(size ==1) {
			return;
		}
		for ( ; i < size-1; i += 2) {
			sb.append(((num[i] - '0') + (num[i+1] - '0')));
			count++;
		}
		if(size%2==1) {
			sb.append((num[size-1]-'0'));
		}
		getResult(sb.toString().toCharArray());
	}

}

© 2019. All rights reserved.

Powered by Hydejack v8.4.0