import java.util.*;
class Main {
public String solution(String str) {
String answer = "YES";
str = str.toUpperCase();
int lt = 0, rt = str.length() - 1;
while (lt < rt) {
if (!Character.isAlphabetic(str.charAt(lt))) {
lt++;
} else if (!Character.isAlphabetic(str.charAt(rt))) {
rt--;
} else if (str.charAt(lt) != str.charAt(rt)) {
answer = "NO";
break;
} else {
lt++;
rt--;
}
}
return answer;
}
public static void main(String[] args) {
Main T = new Main();
Scanner kb = new Scanner(System.in);
System.out.println(T.solution(kb.nextLine()));
}
}
import java.util.*;
class Main {
public String solution(String str) {
String answer = "NO";
str = str.toUpperCase().replaceAll("[^A-Z]", "");
String tmp = new StringBuilder(str).reverse().toString();
if(str.equals(tmp))
answer = "YES";
return answer;
}
public static void main(String[] args) {
Main T = new Main();
Scanner kb = new Scanner(System.in);
System.out.println(T.solution(kb.nextLine()));
}
}
replaceAll("정규식", "")
'알고리즘 > JAVA' 카테고리의 다른 글
10. 가장 짧은 문자거리 (0) | 2021.08.31 |
---|---|
9. 숫자만 추출 (0) | 2021.08.31 |
7. 회문 문자열 (0) | 2021.08.31 |
6. 중복문자제거 (0) | 2021.08.31 |
5. 특정 문자 뒤집기 (0) | 2021.08.31 |
댓글