Skip to content

Commit 1d8aee8

Browse files
committed
[Bronze I] Title: Form a Straight!, Time: 100 ms, Memory: 14172 KB -BaekjoonHub
1 parent c93845f commit 1d8aee8

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.StringTokenizer;
5+
6+
public class Main {
7+
public static void main(String[] args) throws IOException {
8+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
StringTokenizer st = new StringTokenizer(br.readLine());
10+
11+
boolean[] used = new boolean[10];
12+
int min = Integer.MAX_VALUE;
13+
14+
for (int i = 0; i < 5; i++) {
15+
used[Integer.parseInt(st.nextToken())] = true;
16+
}
17+
18+
for (int i = 1; i <= 5; i++) {
19+
int cnt = 0;
20+
for (int j = 0; j < 5; j++) {
21+
if (!used[j + i]) {
22+
cnt++;
23+
}
24+
}
25+
min = Math.min(min, cnt);
26+
}
27+
28+
System.out.print(min);
29+
}
30+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# [Bronze I] Form a Straight! - 34534
2+
3+
[문제 링크](https://www.acmicpc.net/problem/34534)
4+
5+
### 성능 요약
6+
7+
메모리: 14172 KB, 시간: 100 ms
8+
9+
### 분류
10+
11+
구현, 브루트포스 알고리즘
12+
13+
### 제출 일자
14+
15+
2026년 4월 13일 22:36:22
16+
17+
### 문제 설명
18+
19+
<p><img alt="" src="https://upload.acmicpc.net/3152ca96-11ba-4dd9-a757-7ac807e36c31/-/preview/" style="width:50%; height:auto; display:block; margin:auto;"></p>
20+
21+
<p>현석이는 $1$부터 $9$까지의 숫자가 적힌 카드 더미에서 임의로 다섯 장의 카드를 뽑았다. 현석이는 이 카드들을 <strong>스트레이트</strong>로 만들고자 한다.</p>
22+
23+
<p>다섯 장의 카드를 임의로 재배열하여 숫자가 연속으로 이어지도록 할 수 있다면 스트레이트를 만들었다고 본다. 즉, 스트레이트는 아래 다섯 경우 중 하나이다.</p>
24+
25+
<ul>
26+
<li>$[1,2,3,4,5]$</li>
27+
<li>$[2,3,4,5,6]$</li>
28+
<li>$[3,4,5,6,7]$</li>
29+
<li>$[4,5,6,7,8]$</li>
30+
<li>$[5,6,7,8,9]$</li>
31+
</ul>
32+
33+
<p>현석이는 뽑은 카드 중 한 장의 카드에 적힌 숫자를 원하는 숫자로 바꾸는 마법을 얼마든지 부릴 수 있다. 현석이가 뽑은 카드들을 스트레이트로 만들기 위해 최소 몇 번의 마법을 부려야 하는지 구해보자.</p>
34+
35+
### 입력
36+
37+
<p>첫째 줄에 현석이가 뽑은 카드 다섯 장에 적힌 숫자가 공백으로 구분되어 주어진다. 각 숫자는 $1$부터 $9$ 사이의 숫자 중 하나이며, 서로 다르다.</p>
38+
39+
### 출력
40+
41+
<p>뽑은 카드들을 스트레이트로 만들기 위해 최소 몇 번의 마법을 부려야 하는지 출력한다.</p>
42+

0 commit comments

Comments
 (0)