-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask11.java
64 lines (62 loc) · 1.85 KB
/
Task11.java
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
import java.util.Scanner;
import java.util.ArrayList;
public class Task11
{
public static void main(String[] args)
{
Scanner read = new Scanner(System.in);
String turn = read.nextLine();
boolean next = turn.equals("Chewbacca");
char[][] board = new char[3][3];
for(int i=0;i<3;i++)
{
String row = read.nextLine();
board[i] = row.toCharArray();
}
ArrayList<char[]> lines = new ArrayList<>();
lines.add(new char[]{board[0][0],board[0][1],board[0][2]});
lines.add(new char[]{board[1][0],board[1][1],board[1][2]});
lines.add(new char[]{board[2][0],board[2][1],board[2][2]});
lines.add(new char[]{board[0][0],board[1][0],board[2][0]});
lines.add(new char[]{board[0][1],board[1][1],board[2][1]});
lines.add(new char[]{board[0][2],board[1][2],board[2][2]});
lines.add(new char[]{board[0][0],board[1][1],board[2][2]});
lines.add(new char[]{board[0][2],board[1][1],board[2][0]});
boolean open = false;
int numopen = 0;
for(char[] line : lines)
{
if(!(line[0]=='o'||line[1]=='o'||line[2]=='o'))
{
open=true;
numopen++;
}
}
if(next)
{
if(open)
{
System.out.println("yes");
return;
}
else
{
System.out.println("no");
return;
}
}
else if(open)
{
if(numopen>1)
{
System.out.println("yes");
return;
}
else
{
System.out.println("no");
return;
}
}
}
}