
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = br.readLine();
String s = input.replaceAll("pi|ka|chu", "");
if (input.contains("pi") || input.contains("ka") || input.contains("chu") || input.) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
당연히 오답이다. 만약 입력값이 pihello면 YES를 출력한다.
해결책이 떠오르지 않았다.
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = br.readLine();
String s = input.replaceAll("pi|ka|chu", "");
if (s.equals("")) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
// 1. 특정 문자 제거
String cleaned = "Hello, World!".replaceAll("[,!]", "");
// "Hello World"
// 2. 공백 제거
String trimmed = " Hello World ".replaceAll("\\s+", " ").trim();
// "Hello World"
// 3. 숫자만 추출
String numbers = "Hello123World456".replaceAll("[^0-9]", "");
// "123456"
// 4. 대문자만 추출
String uppercase = "Hello123World".replaceAll("[^A-Z]", "");
// "HW"
// 5. 특정 패턴 바꾸기 (예: 케이스 변환)
String swapped = "Hello World".replaceAll("(\\w)(\\w*)", "$1$2_");
// "H_e_l_l_o_ W_o_r_l_d_"
// 6. 여러 패턴을 한 번에 바꾸기
String replaced = "abc123def456ghi".replaceAll("(\\d+)|(\\w)", "$1:$2:");
// "abc:123:def:456:ghi:"
// 7. 구분자로 분리하여 배열로 변환
String[] split = "apple,banana,cherry".split(",");
// ["apple", "banana", "cherry"]