-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2615.java
More file actions
155 lines (136 loc) · 3.83 KB
/
2615.java
File metadata and controls
155 lines (136 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
static final int MAX = 19;
static int win;
static int row, column;
static int[][] map = new int[MAX+1][MAX+1];
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for(int i = 1; i <= MAX; i++) {
String line = reader.readLine();
for(int j = 0; j < MAX; j++) {
map[i][j+1] = line.charAt(j*2) - '0';
}
}
int preRowValue, preRowCount, preColumnValue, preColumnCount;
int leftUpDiagonalValue, leftUpDiagonalCount, leftDownDiagonalValue, leftDownDiagonalCount;
int rightUpDiagonalValue, rightUpDiagonalCount, rightDownDiagonalValue, rightDownDiagonalCount;
for(int i = 1; i <= MAX; i++) {
preRowValue = preColumnValue = 0;
preRowCount = preColumnCount = 0;
int j;
for(j = 1; j <= MAX; j++) {
if(map[i][j] == preRowValue) {
preRowCount++;
}else {
if(preRowCount == 5 && preRowValue != 0) {
break;
}else {
preRowValue = map[i][j];
preRowCount = 1;
}
}
}
if(preRowCount == 5 && preRowValue != 0) {
win = preRowValue;
row = i;
column = j-5;
break;
}
for(j = 1; j <= MAX; j++) {
if(map[j][i] == preColumnValue) {
preColumnCount++;
}else {
if(preColumnCount == 5 && preColumnValue != 0) {
break;
}else {
preColumnValue = map[j][i];
preColumnCount = 1;
}
}
}
if(preColumnCount == 5 && preColumnValue != 0) {
win = preColumnValue;
row = j-5;
column = i;
break;
}
leftUpDiagonalValue = leftUpDiagonalCount = 0;
leftDownDiagonalValue = leftDownDiagonalCount = 0;
int preIndex = 1;
for(j = i; j <= MAX; j++, preIndex++) {
if(map[preIndex][j] == leftUpDiagonalValue) {
leftUpDiagonalCount++;
}else {
if(leftUpDiagonalCount == 5 && leftUpDiagonalValue != 0) {
break;
}else {
leftUpDiagonalValue = map[preIndex][j];
leftUpDiagonalCount = 1;
}
}
if(map[j][preIndex] == leftDownDiagonalValue) {
leftDownDiagonalCount++;
}else {
if(leftDownDiagonalCount == 5 && leftDownDiagonalValue != 0) {
break;
}else {
leftDownDiagonalValue = map[j][preIndex];
leftDownDiagonalCount = 1;
}
}
}
if(leftUpDiagonalCount == 5 && leftUpDiagonalValue != 0) {
win = leftUpDiagonalValue;
row = preIndex -5;
column = j-5;
break;
}else if(leftDownDiagonalCount == 5 && leftDownDiagonalValue != 0) {
win = leftDownDiagonalValue;
row = j - 5;
column = preIndex - 5;
break;
}
rightUpDiagonalValue = rightUpDiagonalCount = 0;
rightDownDiagonalValue = rightDownDiagonalCount = 0;
preIndex = 1;
for(j = i; j >= 1; j--, preIndex++) {
if(map[j][preIndex] == rightUpDiagonalValue) {
rightUpDiagonalCount++;
}else {
if(rightUpDiagonalCount == 5 && rightUpDiagonalValue != 0) {
break;
}else {
rightUpDiagonalValue = map[j][preIndex];
rightUpDiagonalCount = 1;
}
}
if(map[MAX-preIndex+1][MAX-j+1] == rightDownDiagonalValue) {
rightDownDiagonalCount++;
}else {
if(rightDownDiagonalCount == 5 && rightDownDiagonalValue != 0) {
break;
}else {
rightDownDiagonalValue = map[MAX-preIndex+1][MAX-j+1];
rightDownDiagonalCount = 1;
}
}
}
if(rightUpDiagonalCount == 5 && rightUpDiagonalValue != 0) {
win = rightUpDiagonalValue;
row = j + 5;
column = preIndex -5;
break;
}else if(rightDownDiagonalCount == 5 && rightDownDiagonalValue != 0) {
win = rightDownDiagonalValue;
row = MAX -preIndex + 1 + 5;
column = MAX -j +1 - 5;
break;
}
}
System.out.println(win);
if(win != 0)
System.out.println(String.format("%d %d", row, column));
}
}