UVA Solution 422 - Word-Search Wonder Solution in C - Volume 4 - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Tuesday, May 9, 2017

UVA Solution 422 - Word-Search Wonder Solution in C - Volume 4

UVA Solution 422 - Word-Search Wonder Solution in ANSI C - Volume 4

UVA Online Judge Solution 422 - Word-Search Wonder | Volume 4
UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=363

Problem Name: 422 - Word-Search Wonder
Problem Number : UVA - 422 - Word-Search Wonder
Online Judge : UVA Online Judge Solution
Volume: 4
Solution Language : ANSI C

UVA Solution 422 - Word-Search Wonder - Volume 4


UVA Solution 422 - Word-Search Wonder Code in C:


#include <stdio.h>
#include <string.h>
int n, i, j;
int find(char str[], char map[][105]) {
    static int D[][2] = {{0,1},{1,0},{-1,0},{0,-1},
                        {1,1},{1,-1},{-1,1},{-1,-1}};
    int i, j, k, x, y, idx;
    for(i = 0; i < n; i++) {
        for(j = 0; j < n; j++) {
            for(k = 0; k < 8; k++) {
                x = i, y = j, idx = 0;
                while(map[x][y] == str[idx]) {
                    idx++;
                    if(str[idx] == '\0') {
                        printf("%d,%d %d,%d\n", i+1, j+1, x+1, y+1);
                        return 1;
                    }
                    x += D[k][0], y += D[k][1];
                    if(x < 0 || y < 0 || x >= n || y >= n)
                        break;
                }
            }
        }
    }
    return 0;
}

int main() {
    while(scanf("%d", &n) == 1) {
        char map[105][105], str[105];
        for(i = 0; i < n; i++) {
            scanf("%s", &map[i]);
        }
        while(scanf("%s", str) == 1) {
            if(!strcmp(str, "0"))
                break;
            if(!find(str, map))
                puts("Not found");
        }
    }
    return 0;
}

No comments:

Post a Comment