https://www.acmicpc.net/problem/2578
2578번: 빙고
첫째 줄부터 다섯째 줄까지 빙고판에 쓰여진 수가 가장 위 가로줄부터 차례대로 한 줄에 다섯 개씩 빈 칸을 사이에 두고 주어진다. 여섯째 줄부터 열째 줄까지 사회자가 부르는 수가 차례대로
www.acmicpc.net
#include <bits/stdc++.h>
// [C++] 백준 문제풀이 (Simulation)
int map[5][5];
int cmd[25];
void check(int num){
for (int y = 0; y < 5; ++y){
for (int x = 0; x < 5; ++x){
if (map[y][x] == num){
map[y][x] = 0;
return;
}
}
}
}
bool rows(int r) {
for (int j = 0; j < 5; ++j){
if (map[r][j] != 0) return false;
}
return true;
}
bool cols(int c) {
for (int i = 0; i < 5; ++i){
if (map[i][c] != 0) return false;
}
return true;
}
bool lt() {
for (int i = 0; i < 5; ++i){
if (map[i][i] != 0) return false;
}
return true;
}
bool rt() {
for (int i = 0; i < 5; ++i){
if (map[4 - i][i] != 0) return false;
}
return true;
}
bool isBingo(){
int cnt = 0;
for (int i = 0; i < 5; ++i){
if (rows(i)) ++cnt;
if (cols(i)) ++cnt;
}
if (lt()) ++cnt;
if (rt()) ++cnt;
return cnt >= 3;
}
int main(int argc, char *argv[])
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
for (int i = 0; i < 5; ++i){
for (int j = 0; j < 5; ++j){
std::cin >> map[i][j];
}
}
for (int i = 0; i < 25; ++i){
std::cin >> cmd[i];
}
for (int i = 0; i < 25; ++i){
check(cmd[i]);
if (isBingo()){
std::cout << i + 1 << "\n";
break;
}
}
return 0;
}
'백준 문제풀이 > Simulation' 카테고리의 다른 글
[C++] 백준 문제풀이 (Simulation) 20006번 랭킹전 대기열 (2) | 2023.12.03 |
---|---|
[C++] 백준 문제풀이 (Simulation) 11559번 Puyo Puyo (0) | 2023.12.03 |
[C++] 백준 문제풀이 (Simulation) 18808번 스티커 붙이기 (1) | 2023.12.01 |