Dev.baelanche

[백준 9324] 진짜 메세지 본문

Data Structure & Algorithm/PS - JAVA

[백준 9324] 진짜 메세지

baelanche 2019. 4. 27. 19:08
반응형

 

 

입력된 메세지를 알고리즘대로 체크해 새 메세지를 만들어내고 둘을 비교하는 방식으로 풀었다.

 

 

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int t = sc.nextInt();
		
		while(t-->0) {
			String str = sc.next();
			char c[] = str.toCharArray();
			int alpha[] = new int[26];
			
			StringBuilder sb = new StringBuilder();
			for(int i=0; i<c.length; i++) {
				sb.append(c[i]);
				if(++alpha[c[i] - 65] == 3) {
					sb.append(c[i]);
					alpha[c[i] - 65] = 0;
					i++;
				}
			}
			System.out.println(str.equals(sb.toString()) == true ? "OK" : "FAKE");
		}
	}
}
반응형

'Data Structure & Algorithm > PS - JAVA' 카테고리의 다른 글

[백준 1713] 후보 추천하기  (0) 2019.04.27
[백준 2823] 유턴 싫어  (2) 2019.04.27
[백준 3054] 피터팬 프레임  (0) 2019.04.27
[백준 2810] 컵홀더  (0) 2019.04.27
[백준 1773] 폭죽쇼  (0) 2019.04.27
Comments