File tree Expand file tree Collapse file tree 1 file changed +81
-0
lines changed Expand file tree Collapse file tree 1 file changed +81
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .io .*;
2+ import java .util .*;
3+
4+ public class Main {
5+
6+ public static void main (String [] args ) throws IOException {
7+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
8+ int [][] board = new int [5 ][5 ];
9+ for (int i =0 ; i <5 ; i ++) {
10+ StringTokenizer st = new StringTokenizer (br .readLine ());
11+ for (int j =0 ; j <5 ; j ++) {
12+ board [i ][j ] = Integer .parseInt (st .nextToken ());
13+ }
14+ }
15+ int answer = 0 ;
16+ for (int i =0 ; i <5 ; i ++) {
17+ StringTokenizer st = new StringTokenizer (br .readLine ());
18+ for (int j =0 ; j <5 ; j ++) {
19+ int num = Integer .parseInt (st .nextToken ());
20+ removeNumber (board , num );
21+ answer ++;
22+ if (isBingo (board )) {
23+ System .out .println (answer );
24+ return ;
25+ }
26+ }
27+ }
28+ }
29+
30+ public static void removeNumber (int [][] board , int num ) {
31+ for (int i =0 ; i <5 ; i ++) {
32+ for (int j =0 ; j <5 ; j ++) {
33+ if (board [i ][j ] == num ) {
34+ board [i ][j ] = 0 ;
35+ }
36+ }
37+ }
38+ }
39+
40+ public static boolean isBingo (int [][] board ) {
41+ int bingo = 0 ;
42+ // 가로, 세로 카운트
43+ for (int i =0 ; i <5 ; i ++) {
44+ int count1 = 0 ;
45+ int count2 = 0 ;
46+ for (int j =0 ; j <5 ; j ++) {
47+ if (board [i ][j ] == 0 ) {
48+ count1 ++;
49+ }
50+ if (board [j ][i ] == 0 ) {
51+ count2 ++;
52+ }
53+ }
54+ if (count1 == 5 ) {
55+ bingo ++;
56+ }
57+ if (count2 == 5 ) {
58+ bingo ++;
59+ }
60+ }
61+
62+ // 대각선 카운트
63+ int count1 = 0 ;
64+ int count2 = 0 ;
65+ for (int i =0 ; i <5 ; i ++) {
66+ if (board [i ][i ] == 0 ) {
67+ count1 ++;
68+ }
69+ if (board [i ][4 -i ] == 0 ) {
70+ count2 ++;
71+ }
72+ }
73+ if (count1 == 5 ) {
74+ bingo ++;
75+ }
76+ if (count2 == 5 ) {
77+ bingo ++;
78+ }
79+ return bingo >= 3 ;
80+ }
81+ }
You can’t perform that action at this time.
0 commit comments