-
Notifications
You must be signed in to change notification settings - Fork 3
김지수: 햄버거 분배 #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
soojik
wants to merge
1
commit into
Coding-Test-Study-Group:main
Choose a base branch
from
soojik:soojik_햄버거분배
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "soojik_\uD584\uBC84\uAC70\uBD84\uBC30"
Open
김지수: 햄버거 분배 #272
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,64 @@ | ||
package soojik.week15.햄버거분배; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Queue; | ||
import java.util.LinkedList; | ||
import java.util.StringTokenizer; | ||
|
||
public class Main { | ||
// 주어진 데이터 N, K, 식탁 정보 | ||
static int N, K; | ||
static String table; | ||
// 사람과 햄버거 인덱스만 모아놓은 Queue<Integer> persons, hamburgers | ||
static Queue<Integer> persons = new LinkedList<>(); | ||
static Queue<Integer> hamburgers = new LinkedList<>(); | ||
public static void main(String[] args) throws IOException { | ||
System.setIn(new FileInputStream("soojik/week15/햄버거분배/input.txt")); | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
N = Integer.parseInt(st.nextToken()); | ||
K = Integer.parseInt(st.nextToken()); | ||
|
||
table = br.readLine(); | ||
|
||
for (int i = 0; i < N; i++) { | ||
if (table.charAt(i) == 'H') { | ||
hamburgers.add(i); | ||
continue; | ||
} | ||
persons.add(i); | ||
} | ||
|
||
int answer = 0; | ||
|
||
int p, h; | ||
while (!persons.isEmpty()) { | ||
// persons 에서 하나씩 꺼내서 | ||
p = persons.poll(); | ||
|
||
// hamburgers 하나씩 비교 | ||
while (!hamburgers.isEmpty()) { | ||
// 만약 가장 앞 값이 현재 사람이 뒤쪽으로 닿을 수 없는 위치라면 탐색 중단 | ||
// 앞쪽으로 닿을 수 없는 거리의 햄버거라면 이미 앞쪽의 탐색에서 버려졌을 것 | ||
if (p + K < hamburgers.peek()) { | ||
break; | ||
} | ||
|
||
h = hamburgers.poll(); | ||
|
||
// 그 외에 닿을 수 있는 거리면 answer 1 증가시키고 탐색 중단 | ||
if (p - K <= h && h <= p + K) { | ||
++answer; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
System.out.println(answer); | ||
} | ||
} |
This file contains hidden or 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,5 @@ | ||
20 1 | ||
HHPHPPHHPPHPPPHPHPHP | ||
|
||
20 2 | ||
HHHHHPPPPPHPHPHPHHHP |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사람과 햄버거를 queue에 넣으신 거 좋습니다!