-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
const int BINGO_SIZE = 5; | ||
int board[BINGO_SIZE][BINGO_SIZE]; | ||
|
||
void changeBingo(int target); | ||
int checkBingo(); | ||
|
||
|
||
|
||
int main() | ||
{ | ||
ios::sync_with_stdio(0); cin.tie(0); | ||
for (int i = 0; i < BINGO_SIZE; i++) | ||
{ | ||
for (int j = 0; j < BINGO_SIZE; j++) | ||
{ | ||
cin >> board[i][j]; | ||
} | ||
} | ||
|
||
int sayCnt = 0; | ||
for (int i = 0; i < BINGO_SIZE * BINGO_SIZE; i++) | ||
{ | ||
int num; | ||
cin >> num; | ||
sayCnt++; | ||
changeBingo(num); | ||
if (checkBingo() >= 3) { | ||
cout << sayCnt; | ||
return 0; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
|
||
void changeBingo(int target) //์ฌํ์๊ฐ ๋ถ๋ฅธ ์ ์ฒดํฌํ๊ธฐ | ||
{ | ||
for (int i = 0; i < BINGO_SIZE; i++){ | ||
for (int j = 0; j < BINGO_SIZE; j++){ | ||
if (board[i][j] == target){ | ||
board[i][j] = 0; | ||
return; | ||
} | ||
} | ||
} | ||
return; | ||
} | ||
|
||
int checkBingo() //ํ์ฌ ๋ณด๋ํ์ ๋น๊ณ ๊ฐ ๋ช์ค์ธ์ง | ||
{ | ||
int bingoCnt = 0; | ||
|
||
for (int i = 0; i < BINGO_SIZE; i++) //๊ฐ๋ก, ์ธ๋ก ๋น๊ณ ํ์ธ | ||
{ | ||
int horizontal = 0, vertical = 0; | ||
for (int j = 0; j < BINGO_SIZE; j++){ | ||
if (!board[i][j]) | ||
horizontal++; | ||
if (!board[j][i]) | ||
vertical++; | ||
} | ||
if (horizontal == BINGO_SIZE) bingoCnt++; | ||
if (vertical == BINGO_SIZE) bingoCnt++; | ||
} | ||
|
||
int right_diagonal = 0, left_diagonal = 0; | ||
for (int i = 0; i < BINGO_SIZE; i++) //๋๊ฐ์ 2๊ฐ ๋น๊ณ ํ์ธ | ||
{ | ||
if (!board[i][i]) right_diagonal++; | ||
if (!board[i][BINGO_SIZE - i - 1]) left_diagonal++; | ||
} | ||
if (right_diagonal == BINGO_SIZE) bingoCnt++; | ||
if (left_diagonal == BINGO_SIZE) bingoCnt++; | ||
|
||
return bingoCnt; | ||
} |