From d8f1ecc04ab860de057bf33f6bb015e7d993cb28 Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Thu, 30 May 2024 20:45:22 +0900 Subject: [PATCH] =?UTF-8?q?2024-05-30=20=EB=B9=99=EA=B3=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oesnuj/README.md | 1 + "oesnuj/\352\265\254\355\230\204/2578.cpp" | 79 ++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 "oesnuj/\352\265\254\355\230\204/2578.cpp" diff --git a/oesnuj/README.md b/oesnuj/README.md index c49dc46..f16f53f 100644 --- a/oesnuj/README.md +++ b/oesnuj/README.md @@ -10,4 +10,5 @@ | 6차시 | 2024.05.06 | 기하학 | [정사각형](https://www.acmicpc.net/problem/1485) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/22) | | 7차시 | 2024.05.08 | 스택, 큐, 덱 | [queuestack](https://www.acmicpc.net/problem/24511) | [#24](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/24) | | 8차시 | 2024.05.13 | 우선순위 큐 | [카드 정렬하기](https://www.acmicpc.net/problem/1715) | [#27](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/27) | +| 9차시 | 2024.05.30 | 구현 | [빙고](https://www.acmicpc.net/problem/2578) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/30) | --- diff --git "a/oesnuj/\352\265\254\355\230\204/2578.cpp" "b/oesnuj/\352\265\254\355\230\204/2578.cpp" new file mode 100644 index 0000000..04b2adc --- /dev/null +++ "b/oesnuj/\352\265\254\355\230\204/2578.cpp" @@ -0,0 +1,79 @@ +#include +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; +} \ No newline at end of file