동적계획법 대표적인 문제인 WILDCARD 문제 질문입니다. kdh9520 아래 코드와 깉이 하여 샘플 테스트케이스에 대해서는 옮은 답이나오는데 오답 처리가 되네요 어떤 부분을 놓친것일지 고민을 하여도 이해가 되지 않네요 ㅜ #include <iostream> #include <string> #include <cstring> #include <vector> #include <algorithm> #include <limits.h> using namespace std; int testcaseN; string wCString; int numOfWord; string nowWord; string resultWord[50]; int resultCount; bool match(int wCIndex, int wIndex); int main(void){ cin >> testcaseN; for (int i = 0; i < testcaseN; i++){ cin >> wCString; cin >> numOfWord; resultCount = 0; for (int j = 0; j < numOfWord; j++){ cin>>nowWord; if (match(0, 0)){ resultWord[resultCount] = nowWord; resultCount++; } } //정렬 sort(resultWord, resultWord+resultCount); //출력 for (int j = 0; j < resultCount; j++){ cout << resultWord[j] << endl; } } return 0; } bool match(int wCIndex, int wIndex){ //중복되는 별 떙겨주기 if (wCString[wCIndex] == '*'){ while (wCString[wCIndex + 1] == '*'){ wCIndex++; } } if (wCIndex==wCString.length()-1){//와일드카드 마지막 문자이고 if (wCString[wCIndex] == '*'){//그게 *이면 무조건 트루 return true; } else if (wCString[wCIndex] == '?'){//그게 ?이면 if (wIndex == nowWord.length() - 1) return true; else return false; } else{//와일드카드 마지막 글자가 그냥 문자면 if (wIndex == nowWord.length() - 1 &&//현재글자가 마지막글자이고 wCString[wCIndex] == nowWord[wIndex]){//일치하면 return true; } return false; } } if (wCString[wCIndex] == nowWord[wIndex]){//현재것과 일치하면 return match(wCIndex + 1, wIndex + 1); } else if (wCString[wCIndex] == '?'){//?면 return match(wCIndex + 1, wIndex + 1); } else if (wCString[wCIndex] = '*'){//별이지만 마지막이 아닌 경우 char starNext = wCString[wCIndex + 1]; while (starNext != nowWord[wIndex]){//별다음문자와 일치할때까지 ++ wIndex++; if (wIndex > nowWord.length() - 1)//별다음게 일치하는게 없으면 FALSE return false; } return match(wCIndex + 1, wIndex); } return false; } ~~~ 10년 전
0개의 댓글이 있습니다. 정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면 온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야 합니다. 현재 문제를 푸셨습니다.
kdh9520
아래 코드와 깉이 하여 샘플 테스트케이스에 대해서는 옮은 답이나오는데
오답 처리가 되네요
어떤 부분을 놓친것일지 고민을 하여도 이해가 되지 않네요 ㅜ
10년 전