Untitled
unknown
c_cpp
a year ago
2.2 kB
5
Indexable
Never
#include<stdio.h> #include<stdbool.h> bool check(int array[5][5]){ for (int i = 1; i < 4; i++){ for (int j = 1; j < 4; j++){ if (array[i][j] != -100){ if (array[i][j] == array[i + 1][j] && array[i][j] == array[i - 1][j]){ if (array[i][j] == 1) printf("Black wins."); else printf("White wins."); return true; } if (array[i][j] == array[i][j + 1] && array[i][j] == array[i][j - 1]){ if (array[i][j] == 1) printf("Black wins."); else printf("White wins."); return true; } if (array[i][j] == array[i + 1][j + 1] && array[i][j] == array[i - 1][j - 1]){ if (array[i][j] == 1) printf("Black wins."); else printf("White wins."); return true; } if (array[i][j] == array[i + 1][j - 1] && array[i][j] == array[i - 1][j + 1]){ if (array[i][j] == 1) printf("Black wins."); else printf("White wins."); return true; } } } } return false; } int main(){ int a[5][5]; for (int i = 0; i < 5; i++){ for (int j = 0; j < 5; j++) a[i][j] = -100; } int round; scanf("%d", &round); int x; int y; bool player = true; for (int i = 0; i < round; i++){ scanf("%d%d", &x, &y); while (x <= 2 && x >=0 && y >= 0 && y <= 2 && a[3 - y][x + 1] == -100){ if (player) a[3 - y][x + 1] = 1; else a[3 - y][x + 1] = 0; player = (player)? false:true; } if (check(a)) break; } if (check(a) == false) printf("There is a draw."); }