슈콩

[SWEA] 회문의 회문 본문

카테고리 없음

[SWEA] 회문의 회문

shukong 2025. 11. 14. 19:49

 

 

[문제]

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AY2hjCWKbykDFATh

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Solution {
	static String str;
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			str = br.readLine();
			boolean result = false;
			if(str.length()%2==0) {
				if(check(0,str.length()) && check(0,str.length()/2) && check(str.length()/2,str.length())) {
					result = true;
				}
			}
			else {
				if(check(0,str.length()) && check(0,str.length()/2) && check(str.length()/2+1,str.length())) {
					result = true;
				}
			}
			if(result) 
				System.out.println("#"+tc+" YES");
			else
				System.out.println("#"+tc+" NO");
		}
	}
	private static boolean check(int start,int end) {
		for(int i=start;i<(end-start)/2;i++) {
			if(str.charAt(start+i)!=str.charAt(end-1-i))
				return false;
		}
		return true;
	}
}