BRACKET2 오답인 이유를 모르겠습니다. 도와주세요

  • susul89
    susul89

    괄호를 순서대로 맞추는 BRACKET2계속 오답이 나네요.
    문제에 나와있는 case나 댓글에 적어주신 case모두
    알맞게 답이 출력이 되는데 무엇떄문에 오답이 나는 것인지 모르겠습니다.
    알고리즘의 원리는
    왼쪽괄호를 차례대로 쌓고, 오른쪽 괄호를 또 차례대로 쌓고
    가장 마지막에 있는 녀석끼리 비교를 하게 되며
    cross를 막기 위해서
    딱 스트링의 숫자만큼 반복해서 다 제거되지 않으면
    No가 나오게 만들었습니다.

    #include <iostream>
    #include<string>
    #include <string.h>
    #include <cstdlib>
    
    
    using namespace std;
    
    char First[2] = { '[', ']' };
    char Second[2] = { '(', ')' };
    char Third[2] = { '{', '}' };
    
    bool AnswerCheck(char A, char B);
    
    int main()
    {
        int Count;
        cin >> Count;
        while (Count--)
        {
            char Left_List[10005];
            char Right_List[10005];
            int MaxLeft = 0;
            int MaxRight = 0;
            string Input;
            cin >> Input;
    
            for (int i = 0; i < Input.length(); i++)
            {
    
                if (Input[i] == First[0] || Input[i] == Second[0] || Input[i] == Third[0])
                {
                    Left_List[MaxLeft] = Input[i];
                    MaxLeft++;
                }
                if (Input[i] == First[1] || Input[i] == Second[1] || Input[i] == Third[1])
                {
                    Right_List[MaxRight] = Input[i];
                    MaxRight++;
                }
                if (MaxLeft>0 && MaxRight>0)
                {
                    if (AnswerCheck(Left_List[MaxLeft - 1], Right_List[MaxRight - 1]))
                    {
                        MaxRight--;
                        MaxLeft--;
                    }
                }
    
            }
            if (MaxRight == 0 && MaxLeft == 0)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
    }
    bool AnswerCheck(char A, char B)
    {
        if (A == First[0])
        { 
            if (B == First[1])
                return true;
            else
                return false;
        }
        if (A == Second[0])
        {
            if (B == Second[1])
                return true;
            else
                return false;
        }
        if (A == Third[0])
        {
            if (B == Third[1])
                return true;
            else
                return false;
        }
    
    }
    }
    

    8년 전
1개의 댓글이 있습니다.
  • fleo0917
    fleo0917

    )(


    8년 전 link
  • 정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면 온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야 합니다. 현재 문제를 푸셨습니다.