[BOJ 18406] 럭키 스트레이트

업데이트:

문제

  • BOJ 18406
  • 문제의 저작권은 Baekjoon Online Judge에 있습니다.

접근방식

숫자들을 입력받아서 중간 인덱스를 기준으로 왼쪽 숫자들의 합, 오른쪽 숫자들의 합을 구해 같은지 비교하면 된다.

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

public class Main {
	
	static String input;
	static int midIdx;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    input = br.readLine();
		
	    midIdx = input.length() / 2;
	    
	    System.out.println( sum(0, midIdx) == sum(midIdx, input.length()) ? "LUCKY" : "READY");
	}
	
	public static int sum( int start, int end ) {
		int sum = 0;
		for(int i=start; i<end; i++) sum += input.charAt(i) - '0';
		return sum;
	}
}

태그:

카테고리:

업데이트: