Boggle
2014-06-25 21:50:01

#define N 5

char boggle[N][N+1]={

    {"URLPM"},

    {"XPRET"},

    {"GIAET"},

    {"XTNZY"},

    {"XOQRS"}

};

int wordN = 6;

bool hasWord(int x, int y, int depth, const char* word){

    if(x<0 || x>=N || y <0 || y >= N){

        return false;

    }

    

    bool hasWordValue = boggle[x][y]==word[depth];

    if(!hasWordValue) return hasWordValue;

    if(depth==wordN-1) return hasWordValue;

    if(hasWord(x+1,y+1,depth+1,word)){return true;}

    if(hasWord(x+1,y-1,depth+1,word)){return true;}

    if(hasWord(x-1,y-1,depth+1,word)){return true;}

    if(hasWord(x-1,y+1,depth+1,word)){return true;}

    if(hasWord(x+1,y,depth+1,word)){return true;}

    if(hasWord(x-1,y,depth+1,word)){return true;}

    if(hasWord(x,y+1,depth+1,word)){return true;}

    if(hasWord(x,y-1,depth+1,word)){return true;}

    return false;

}

int main(){

    char word[10]="PRETTY";

    if(hasWord(1,1,0,word)){

        printf("%s exists

",word);

    }

    return 0;

}

▼ more
와아 곰이다
2014-06-20 21:12:28

▼ more
편집 거리
2014-06-17 22:33:11

치환 : shot -> spot

삽입 : ago -> agog

삭제 : hour -> our

▼ more
그건 늘 그래
2014-06-17 20:04:27

가지 못하는게 아니라

조금 더 가지 않았던 것 뿐이고

그리고 주위를 맴돌거나 왔다갔다 하는 것은

처음에는 마음은 편하지만

결국 목적지에서 더 멀어지게 할 뿐이야

▼ more