Home 백준 9996 한국이 그리울 땐 서버에 접속하지
Post
Cancel

백준 9996 한국이 그리울 땐 서버에 접속하지

문제 출처
https://www.acmicpc.net/problem/9996

오답 풀이

1
패턴을 * 을 기준으로 split 하고 나눠진 문자열을 변수에 할당한다.
할당 된 두 문자열이 앞으로 입력 받을 문자열의 앞과 뒤에 각각 존재하면 정답이다.

오답 원인

2
위 풀이대로만 코드를 작성할 시 패턴이 ab*ab 인 경우 반례가 발생한다.
반례를 해결하는 여러가지 방법 중 가장 간단한 해결 방법으로는 문자열 길이 검사가 있다.

추가적으로 주황색으로 색칠한 교정한 부분도 틀려서 수정한 부분이다..

정답 코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <bits/stdc++.h>

using namespace std;

int main() {
    string str, first, last;
    int idx, k;
    vector<string> ret;
    
    cin >> k; // 반복 횟수
    cin >> str; // str : 패턴
    // 패턴 쪼개기
    idx = str.find("*");
    first = str.substr(0, idx);
    last = str.substr(idx+1);
    
    for(int i = 0; i < k ; ++i) {
        cin >> str; // 이제 str 에는 검사할 값이 들어온다 
        if(str.length() < first.length() + last.length()) {
            ret.push_back("NE"); 
        }
        else {
            if(first.compare(str.substr(0, idx)) == 0 && last.compare(str.substr(str.length()-last.length())) == 0)
                    ret.push_back("DA"); // Yes
            else
                ret.push_back("NE"); // No
        }
    }
    for(string s : ret)
        cout << s << "\n";
    return 0;
}
This post is licensed under CC BY 4.0 by the author.

[Intellij] Cannot resolve symbol

[java] 중첩 클래스 의미, 선언방법