|
| 1 | +#include <iostream> |
| 2 | +#include <vector> |
| 3 | +#include <cstring> |
| 4 | +#include <cstdio> |
| 5 | + |
| 6 | +using namespace std; |
| 7 | + |
| 8 | +// 五子棋,黑色棋子先手 |
| 9 | +vector<string>ve; |
| 10 | +char next_step; |
| 11 | + |
| 12 | +int tran(int x, int y) { |
| 13 | + int cnt = 0, nx = x, ny = y - 1; |
| 14 | + while(ny >= 0 && ve[nx][ny] == next_step) |
| 15 | + { |
| 16 | + cnt++; |
| 17 | + ny--; |
| 18 | + } |
| 19 | + ny = y + 1; |
| 20 | + while(ny < 25 && ve[nx][ny] == next_step) |
| 21 | + { |
| 22 | + cnt++; |
| 23 | + ny++; |
| 24 | + } |
| 25 | + if(cnt >= 4) return 1; |
| 26 | + else return 0; |
| 27 | +} |
| 28 | + |
| 29 | +bool vertical(int x, int y) |
| 30 | +{ |
| 31 | + int cnt = 0, nx = x - 1, ny = y; |
| 32 | + while(nx >= 0 && ve[nx][ny] == next_step) |
| 33 | + { |
| 34 | + cnt++; |
| 35 | + nx--; |
| 36 | + } |
| 37 | + nx = x + 1; |
| 38 | + while(nx < 25 && ve[nx][ny] == next_step) |
| 39 | + { |
| 40 | + cnt++; |
| 41 | + nx++; |
| 42 | + } |
| 43 | + if(cnt >= 4) return 1; |
| 44 | + else return 0; |
| 45 | +} |
| 46 | + |
| 47 | +bool MainDiagonal(int x, int y) |
| 48 | +{ |
| 49 | + int cnt = 0, nx = x - 1, ny = y - 1; |
| 50 | + while(nx >= 0 && ny >= 0 && ve[nx][ny] == next_step) |
| 51 | + { |
| 52 | + cnt++; |
| 53 | + nx--; |
| 54 | + ny--; |
| 55 | + } |
| 56 | + nx = x + 1, ny = y + 1; |
| 57 | + while(nx < 25 && ny < 25 && ve[nx][ny] == next_step) |
| 58 | + { |
| 59 | + cnt++; |
| 60 | + nx++; |
| 61 | + ny++; |
| 62 | + } |
| 63 | + if(cnt >= 4) return 1; |
| 64 | + else return 0; |
| 65 | +} |
| 66 | + |
| 67 | +bool SubDiagonal(int x, int y) |
| 68 | +{ |
| 69 | + int cnt = 0, nx = x - 1, ny = y + 1; |
| 70 | + while(nx >= 0 && ny < 25 && ve[nx][ny] == next_step) |
| 71 | + { |
| 72 | + cnt++; |
| 73 | + nx--; |
| 74 | + ny++; |
| 75 | + } |
| 76 | + nx = x + 1, ny = y - 1; |
| 77 | + while(nx < 25 && ny >= 0 && ve[nx][ny] == next_step) |
| 78 | + { |
| 79 | + cnt++; |
| 80 | + nx++; |
| 81 | + ny--; |
| 82 | + } |
| 83 | + if(cnt >= 4) return 1; |
| 84 | + else return 0; |
| 85 | +} |
| 86 | + |
| 87 | +int main(int argc, char const *argv[]) |
| 88 | +{ |
| 89 | + |
| 90 | + int n; |
| 91 | + string s; |
| 92 | + for(int i = 0; i < 25; i++) { |
| 93 | + cin >> s; |
| 94 | + ve.push_back(s); |
| 95 | + } |
| 96 | + int white = 0, black = 0; |
| 97 | + for(int i = 0; i < 25; i++) { |
| 98 | + for(int j = 0; j < 25; j++) { |
| 99 | + if(ve[i][j] == 'o') { |
| 100 | + white++; |
| 101 | + } |
| 102 | + if(ve[i][j] == 'x') { |
| 103 | + black++; |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + if(white == black) { |
| 108 | + next_step = 'x'; |
| 109 | + } |
| 110 | + else { |
| 111 | + next_step = 'o'; |
| 112 | + } |
| 113 | + vector< pair<int,int> >ans; |
| 114 | + for(int i = 0; i < 25; i++) { |
| 115 | + for(int j = 0; j < 25; j++) { |
| 116 | + if(ve[i][j] == '.') { |
| 117 | + if(tran(i, j) || vertical(i, j) || MainDiagonal(i, j) || SubDiagonal(i, j)) { |
| 118 | + ans.push_back(make_pair(i, j)); |
| 119 | + } |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | + if(ans.size() == 0) { |
| 124 | + cout << "tie" << endl; |
| 125 | + return 0; |
| 126 | + } |
| 127 | + else { |
| 128 | + for(int i = 0; i < (int)ans.size(); i++) { |
| 129 | + cout << ans[i].first << " " << ans[i].second << endl; |
| 130 | + } |
| 131 | + } |
| 132 | + return 0; |
| 133 | +} |
0 commit comments