---
# System prepended metadata

title: 13637 - Easy Gomoku Validator
tags: [array]

---

# 13637 - Easy Gomoku Validator
>author: Utin
###### tags: `array`

---

## Brief
See the code below

## Solution 0

```c=
#include<stdio.h>

int x[16][16] = {0};

int check1(int r, int c, int p) {
    int sum = 1;
    for(int i=1; i<5; i++) {
        if(r+i < 15 && x[r+i][c] == p) sum += 1;
        else break;
    }
    for(int i=1; i<5; i++) {
        if(r-i >= 0 && x[r-i][c] == p) sum += 1;
        else break;
    }
    if(sum >= 5) return 1;
    else return 0;
}

int check2(int r, int c, int p) {
    int sum = 1;
    for(int j=1; j<5; j++) {
        if(c+j < 15 && x[r][c+j] == p) sum += 1;
        else break;
    }
    for(int j=1; j<5; j++) {
        if(c-j >= 0 && x[r][c-j] == p) sum += 1;
        else break;
    }
    if(sum >= 5) return 1;
    else return 0;
}

int check3(int r, int c, int p) {
    int sum = 1;
    for(int j=1; j<5; j++) {
        if(c+j < 15 && r+j < 15 && x[r+j][c+j] == p) sum += 1;
        else break;
    }
    for(int j=1; j<5; j++) {
        if(c-j >= 0 && r-j >= 0 && x[r-j][c-j] == p) sum += 1;
        else break;
    }
    if(sum >= 5) return 1;
    else return 0;
}

int check4(int r, int c, int p) {
    int sum = 1;
    for(int j=1; j<5; j++) {
        if(c+j < 15 && r-j >= 0 && x[r-j][c+j] == p) sum += 1;
        else break;
    }
    for(int j=1; j<5; j++) {
        if(c-j >= 0 && r+j < 1 && x[r+j][c-j] == p) sum += 1;
        else break;
    }
    if(sum >= 5) return 1;
    else return 0;
}

int main() {
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++) {
        int r, c;
        scanf("%d %d", &r, &c);
        r -= 1;
        c -= 1;
        if(i%2 == 0) x[r][c] = 1;
        else x[r][c] = -1;
        if(check1(r, c, x[r][c]) == 1 || check2(r, c, x[r][c]) == 1 || check3(r, c, x[r][c]) == 1 || check4(r, c, x[r][c]) == 1) {
            if(x[r][c] == 1) printf("LSC wins at the %dth step.\n", i+1);
            else printf("TSC wins at the %dth step.\n", i+1);
            break;
        }
        else if(i == n-1) printf("There's no winner.\n");
    }
}
// By Utin
```

## Reference