앞에서 읽을 때나 뒤에서 읽을 때나 같은 문자열을 팰린드롬이라고 합니다.
문자열이 입력되었을 때, 해당 문자열이 팰린드롬이면 "YES", 아니면 "NO"를 출력하는 프로그램을 작성하세요. 단 회문을 검사할 때 알파벳만 가지고 회문을 검사하며, 대소문자를 구분하지 않습니다. 알파벳 이외의 문자는 무시합니다.
found7, time: study; Yduts; emit, 7Dnuof
YES
import java.util.*;
class Main {
public String solution(String s) {
String answer = "NO";
// replace()는 정규식 사용불가, replaceAll()은 정규식 사용 가능
s = s.toUpperCase().replaceAll("[^A-Z]", ""); //A-Z를 제외한 나머지 문자 처리
String tmp = new StringBuilder(s).reverse().toString();
if ( s.equals(tmp) ) answer = "YES";
return answer;
}
public static void main(String[] args) {
Main T = new Main();
Scanner kb = new Scanner(System.in);
String str = kb.next();
System.out.print(T.solution(str));
}
}