Skip to content

Commit f9dd333

Browse files
committed
[Silver IV] Title: 빙고, Time: 140 ms, Memory: 16236 KB -BaekjoonHub
1 parent 29aa30d commit f9dd333

2 files changed

Lines changed: 152 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# [Silver IV] 빙고 - 2578
2+
3+
[문제 링크](https://www.acmicpc.net/problem/2578)
4+
5+
### 성능 요약
6+
7+
메모리: 16236 KB, 시간: 140 ms
8+
9+
### 분류
10+
11+
구현, 시뮬레이션
12+
13+
### 제출 일자
14+
15+
2026년 1월 28일 15:12:54
16+
17+
### 문제 설명
18+
19+
<p>빙고 게임은 다음과 같은 방식으로 이루어진다.</p>
20+
21+
<p>먼저 아래와 같이 25개의 칸으로 이루어진 빙고판에 1부터 25까지 자연수를 한 칸에 하나씩 쓴다</p>
22+
23+
<p style="text-align: center;"><img alt="" src="https://upload.acmicpc.net/5e2e03f0-5561-43c3-9b65-a752837732ef/-/preview/" style="width: 179px; height: 167px;"></p>
24+
25+
<p>다음은 사회자가 부르는 수를 차례로 지워나간다. 예를 들어 5, 10, 7이 불렸다면 이 세 수를 지운 뒤 빙고판의 모습은 다음과 같다.</p>
26+
27+
<p style="text-align: center;"><img alt="" src="https://upload.acmicpc.net/6fc024b4-5bf7-42de-b303-406db2e3ff5b/-/preview/" style="width: 179px; height: 167px;"></p>
28+
29+
<p>차례로 수를 지워가다가 같은 가로줄, 세로줄 또는 대각선 위에 있는 5개의 모든 수가 지워지는 경우 그 줄에 선을 긋는다.</p>
30+
31+
<p style="text-align: center;"><img alt="" src="https://upload.acmicpc.net/b5ffac7e-7db4-4d54-bf2b-63ac7d6807d8/-/preview/" style="width: 218px; height: 218px;"></p>
32+
33+
<p>이러한 선이 세 개 이상 그어지는 순간 "빙고"라고 외치는데, 가장 먼저 외치는 사람이 게임의 승자가 된다.</p>
34+
35+
<p style="text-align: center;"><img alt="" src="https://upload.acmicpc.net/f86e3bcc-54da-420a-8f06-9600cb06eeaa/-/preview/" style="width: 237px; height: 218px;"></p>
36+
37+
<p>철수는 친구들과 빙고 게임을 하고 있다. 철수가 빙고판에 쓴 수들과 사회자가 부르는 수의 순서가 주어질 때, 사회자가 몇 번째 수를 부른 후 철수가 "빙고"를 외치게 되는지를 출력하는 프로그램을 작성하시오.</p>
38+
39+
### 입력
40+
41+
<p>첫째 줄부터 다섯째 줄까지 빙고판에 쓰여진 수가 가장 위 가로줄부터 차례대로 한 줄에 다섯 개씩 빈 칸을 사이에 두고 주어진다. 여섯째 줄부터 열째 줄까지 사회자가 부르는 수가 차례대로 한 줄에 다섯 개씩 빈 칸을 사이에 두고 주어진다. 빙고판에 쓰여진 수와 사회자가 부르는 수는 각각 1부터 25까지의 수가 한 번씩 사용된다.</p>
42+
43+
### 출력
44+
45+
<p>첫째 줄에 사회자가 몇 번째 수를 부른 후 철수가 "빙고"를 외치게 되는지 출력한다.</p>
46+
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
static int arr[][];
6+
static int bingo;
7+
public static void main(String[] args) throws Exception {
8+
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
11+
StringTokenizer st;
12+
arr = new int[5][5];
13+
for(int i =0; i<5; i++) {
14+
st = new StringTokenizer(br.readLine());
15+
for(int j =0; j<5; j++) {
16+
arr[i][j] = Integer.parseInt(st.nextToken());
17+
}
18+
}
19+
bingo = 0;
20+
int count = 0;
21+
for(int i =0; i<5; i++) {
22+
st = new StringTokenizer(br.readLine());
23+
for(int j =0; j<5; j++) {
24+
int n = Integer.parseInt(st.nextToken());
25+
count+=1;
26+
for(int x= 0; x<5; x++) {
27+
for(int y = 0; y<5; y++) {
28+
if(arr[x][y] == n) {
29+
arr[x][y] =0;
30+
}
31+
}
32+
}
33+
34+
35+
xCheck();
36+
yCheck();
37+
xyCheck();
38+
yxCheck();
39+
40+
if (bingo >=3) {
41+
System.out.println(count);
42+
System.exit(0);
43+
}
44+
bingo=0;
45+
}
46+
}
47+
}
48+
49+
public static void xCheck() {
50+
for(int i =0; i<5; i++) {
51+
int count = 0;
52+
53+
for(int j =0; j<5; j++) {
54+
if(arr[i][j] ==0) {
55+
count+=1;
56+
}
57+
}
58+
59+
if(count ==5) {
60+
bingo+=1;
61+
}
62+
}
63+
}
64+
65+
public static void yCheck() {
66+
for(int i =0; i<5; i++) {
67+
int count = 0;
68+
69+
for(int j =0; j<5; j++) {
70+
if(arr[j][i] ==0) {
71+
count+=1;
72+
}
73+
}
74+
75+
if(count ==5) {
76+
bingo+=1;
77+
}
78+
}
79+
}
80+
81+
public static void xyCheck() {
82+
int count = 0;
83+
for(int i=0; i<5; i++) {
84+
if(arr[i][i] == 0) {
85+
count+=1;
86+
}
87+
}
88+
89+
if (count == 5) {
90+
bingo+=1;
91+
}
92+
}
93+
94+
public static void yxCheck() {
95+
int count = 0;
96+
for(int i=0; i<5; i++) {
97+
if(arr[i][4-i] == 0) {
98+
count+=1;
99+
}
100+
}
101+
102+
if (count == 5) {
103+
bingo+=1;
104+
}
105+
}
106+
}

0 commit comments

Comments
 (0)