BOGGLE//RTE (SIGABRT: program aborted, probably assertion fail)

  • vi1409
    vi1409

    BOGGLE

    RTE (SIGABRT: program aborted, probably assertion fail)
    이 에러가 나오는데 어디가 문제인지 도저히 모르겠습니다 ㅠㅠ

    #include<stdio.h>
    #include<cstring>
    #include <algorithm>
    #include <vector>
    using namespace std;
    vector<int> myvec;
    char board[7][7];
    char voca[12];
    int vocalen;
    int dx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
    int dy[] = { -1, -1, -1, 0, 1, 1, 1, 0 };
    bool search(int vocaIndex, int len, int y, int x){
        bool result = false;
        bool thereIS = false;
        if (vocalen == len)
            return true;
        int size = myvec.size() - 1;
        for (int vecIndex = 0; vecIndex < size; vecIndex += 2){
            int popy = myvec[vecIndex + 1];
            int popx = myvec[vecIndex];
            for (int i = 0; i < 8; i++){
                if (voca[vocaIndex] == board[popy + dy[i]][popx + dx[i]]){
                    if (popy + dy[i] != y || popx + dx[i] != x){
                        myvec.push_back(popx + dx[i]); myvec.push_back(popy + dy[i]);
                        thereIS = true;
                    }
                }
            }
        }
        if (thereIS == true){
            thereIS = false;
            result = search(++vocaIndex, ++len, myvec[myvec.size() - 1], myvec[myvec.size() - 2]);
        }
        else
            return false;
    
        return result;
    }
    int main(){
        //freopen("input.txt", "r", stdin);
        int testCase; scanf("%d", &testCase);
        while (testCase--){
            memset(board, '1', sizeof(board));
            for (int i = 1; i < 6; i++){
                getchar();
                for (int j = 1; j < 6; j++)
                    scanf("%c", &board[i][j]);
            }
            int vocaNum; scanf("%d", &vocaNum);
            while (vocaNum--){
                myvec.clear();
                bool result = false;
                scanf("%s", voca);
                vocalen = strlen(voca);
                for (int i = 1; i < 6; i++){
                    for (int j = 1; j < 6; j++){
                        if (voca[0] == board[i][j]){
                            myvec.push_back(j); myvec.push_back(i);
                        }
                    }
                }
                int x = 1;
                if (!myvec.empty())
                    result = search(1, 1, myvec[myvec.size() - 1], myvec[myvec.size() - 2]);
                result == false ? printf("%s NO\n", voca) : printf("%s YES\n", voca);
            }
        }
        return 0;
    }
    

    9년 전
2개의 댓글이 있습니다.
  • JongMan
    JongMan

    myVec에 원소가 계속 추가되면서 메모리를 무한정 먹고 있는 것 같은데요?


    9년 전 link
  • vi1409
    vi1409

    아 감사합니다! ㅎㅎ


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