본문 바로가기
알고리즘 & 자료구조/백준

백준 9996

by 신재권 2022. 2. 3.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main9996 {

	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine()); //파일의 개수 N
		
		String[] s = new String[N];
		String p = br.readLine();

		for(int i=0; i<N; i++) {
			s[i] = br.readLine();
			String prefix = "";
			String suffix = "";
			int state = 0;
			for(int j=0; j<p.length(); j++) {
				if(p.charAt(j) == '*') {
					state = 1;
				}else if(p.charAt(j) != '*' && state == 0) {
					prefix += p.charAt(j);
				}else if(p.charAt(j) != '*' && state == 1) {
					suffix += p.charAt(j);
				}
			}

			s[i] = s[i].replaceFirst(prefix, "*");		
			s[i] = s[i].replace(suffix, "*");
			if(s[i].charAt(0) == '*' && s[i].charAt(s[i].length()-1) == '*') {
				System.out.println("DA");
			}else{
				System.out.println("NE");
			}
		}
		
		
	}
	
	
	
}

'알고리즘 & 자료구조 > 백준' 카테고리의 다른 글

백준 1620  (0) 2022.02.05
백준 2559_1  (0) 2022.02.04
백준 11655  (0) 2022.02.02
백준 10988_1  (0) 2022.02.01
백준 1159  (0) 2022.01.31