728x90
BOJ9996
https://www.acmicpc.net/problem/9996
이 문제는 패턴 문자열의 *를 기준으로 앞부분과 뒷부분을 나누고, 각 파일 이름이 앞부분으로 시작하고 뒷부분으로 끝나는지를 확인해야 합니다. 파일 이름이 앞부분으로 시작하고, 뒷부분으로 끝나면 "DA", 아니면 "NE".
package hanghee99_Middler;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class hh08_BOJ9996 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String pattern = br.readLine();
/// * 기준으로 앞뒤 나누기
int starIndex = pattern.indexOf('*'); /// *가 몇 번째에 있는지 찾기
String prefix = pattern.substring(0, starIndex); /// 시작부터 *까지
String suffix = pattern.substring(starIndex + 1); /// *부터 끝까지
for (int i = 0; i < n; i++) {
String fileName = br.readLine();
if (fileName.length() < prefix.length() + suffix.length()) {
System.out.println("NE");
continue;
}
/// 파일이름이 prefix로 시작하며, 파일 이름이 suffix로 끝나는 메서드
boolean matches = fileName.startsWith(prefix) && fileName.endsWith(suffix);
System.out.println(matches ? "DA" : "NE");
}
}
}
728x90
'알고리즘 > 항해99 알고리즘' 카테고리의 다른 글
항해99 미들러 알고리즘 10일차 (0) | 2025.04.13 |
---|---|
항해99 미들러 알고리즘 9일차 (0) | 2025.04.10 |
항해99 미들러 알고리즘 7일차 (0) | 2025.04.08 |
항해99 미들러 알고리즘 6일차 (0) | 2025.04.07 |
한 페이지로 끝내는 DFS/BFS (0) | 2025.04.07 |