-
Notifications
You must be signed in to change notification settings - Fork 0
[Week05] 덱 / 정다희 #21
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
daheenamic
wants to merge
5
commits into
main
Choose a base branch
from
dahee
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.
Open
[Week05] 덱 / 정다희 #21
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
52 changes: 52 additions & 0 deletions
52
algorithm-study/src/main/java/week05/boj13417/카드문자열_정다희.java
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,52 @@ | ||
| package week05.boj13417; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.util.ArrayDeque; | ||
| import java.util.Deque; | ||
| import java.util.StringTokenizer; | ||
|
|
||
| /** | ||
| * BOJ 13417 카드 문자열 | ||
| * 메모리: 33460KB | ||
| * 시간: 304ms | ||
| * | ||
| * @author dahee | ||
| */ | ||
| public class 카드문자열_정다희 { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| StringBuilder sb = new StringBuilder(); | ||
|
|
||
| // 총 테스트 수 | ||
| int testCount = Integer.parseInt(br.readLine()); | ||
|
|
||
| for (int i = 0; i < testCount; i++) { | ||
| int cardCount = Integer.parseInt(br.readLine()); // 카드의 수 | ||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
| Deque<Character> cards = new ArrayDeque<>(); // 카드를 새로운 문자열로 만들 Deque | ||
|
|
||
| for (int j = 0; j < cardCount; j++) { | ||
| char card = st.nextToken().charAt(0); // 알파벳 순서 비교를 위해 char로 변환 | ||
| if (cards.isEmpty() || card > cards.peekFirst()) { | ||
| // 1. 첫 카드 이거나 | ||
| // 2. 맨 앞 카드가 현재 카드보다 알파벳이 뒤의 순서일 경우 | ||
| cards.addLast(card); // 마지막에 추가 | ||
| } else { | ||
| // 1. 첫 카드가 아니거나 | ||
| // 2. 맨 앞 카드가 현재 카드보다 앞의 순서이거나 | ||
| // 3. 맨 앞 카드와 현재 카드가 같은 알파벳일 경우 | ||
| cards.addFirst(card); // 앞에 추가 | ||
| } | ||
| } | ||
|
|
||
| // Dequq에 넣은 카드를 차례대로 StringBuilder에 append | ||
| for (Character card : cards) sb.append(card); | ||
| // 마지막 카드면 줄바꿈 | ||
| if (i < testCount - 1) sb.append("\n"); | ||
| } | ||
|
|
||
| System.out.println(sb); | ||
| } | ||
| } |
70 changes: 70 additions & 0 deletions
70
algorithm-study/src/main/java/week05/boj20301/반전요세푸스_정다희.java
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,70 @@ | ||
| package week05.boj20301; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.util.ArrayDeque; | ||
| import java.util.Deque; | ||
| import java.util.StringTokenizer; | ||
|
|
||
| /** | ||
| * BOJ 20301 반전 요세푸스 | ||
| * 메모리: 18032KB | ||
| * 시간: 260ms | ||
| * | ||
| * @author dahee | ||
| */ | ||
| public class 반전요세푸스_정다희 { | ||
| static BufferedReader br; | ||
| static StringTokenizer st; | ||
| static StringBuilder sb; | ||
|
|
||
| static int totalPeople, stepSize, reverse, killCount; | ||
| static boolean isReversed; | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| init(); | ||
| killStart(); | ||
| System.out.println(sb.toString()); | ||
| } | ||
|
|
||
| static void killStart() { | ||
| Deque<Integer> deque = new ArrayDeque<>(); | ||
|
|
||
| for (int i = 1; i <= totalPeople; i++) { | ||
| deque.addLast(i); | ||
| } | ||
|
|
||
| while (!deque.isEmpty()) { | ||
| if (!isReversed) { | ||
| for (int i = 0; i < stepSize - 1; i++) { | ||
| deque.addLast(deque.pollFirst()); | ||
| } | ||
| sb.append(deque.removeFirst()).append("\n"); | ||
| } else { | ||
| for (int i = 0; i < stepSize - 1; i++) { | ||
| deque.addFirst(deque.pollLast()); | ||
| } | ||
| sb.append(deque.removeLast()).append("\n"); | ||
| } | ||
| killCount++; | ||
| applyReverseInterval(); | ||
| } | ||
| } | ||
|
|
||
| public static void applyReverseInterval () { | ||
| if (reverse > 0 && killCount % reverse == 0) { | ||
| isReversed = !isReversed; | ||
| } | ||
| } | ||
|
|
||
| static void init() throws IOException { | ||
| br = new BufferedReader(new InputStreamReader(System.in)); | ||
| sb = new StringBuilder(); | ||
| st = new StringTokenizer(br.readLine()); | ||
|
|
||
| totalPeople = Integer.parseInt(st.nextToken()); | ||
| stepSize = Integer.parseInt(st.nextToken()); | ||
| reverse = Integer.parseInt(st.nextToken()); | ||
| } | ||
| } | ||
53 changes: 53 additions & 0 deletions
53
algorithm-study/src/main/java/week05/boj2346/풍선터뜨리기_정다희.java
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,53 @@ | ||
| package week05.boj2346; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.util.ArrayDeque; | ||
| import java.util.Deque; | ||
| import java.util.StringTokenizer; | ||
|
|
||
| /** | ||
| * BOJ 2346 풍선 터뜨리기 | ||
| * 메모리: 14560KB | ||
| * 시간: 152ms | ||
| * | ||
| * @author dahee | ||
| */ | ||
| public class 풍선터뜨리기_정다희 { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| StringBuilder sb = new StringBuilder(); | ||
|
|
||
| int count = Integer.parseInt(br.readLine()); | ||
| Deque<Integer> deque = new ArrayDeque<>(); | ||
| int[] arr = new int[count]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 번호를 배열로 처리하는 방법도 있었네요 ..! 배워갑니다 :) |
||
|
|
||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
|
||
| for (int i = 0; i < count; i++) { | ||
| arr[i] = Integer.parseInt(st.nextToken()); | ||
| deque.offer(i+1); | ||
| } | ||
|
|
||
| while(!deque.isEmpty()) { | ||
| int idx = deque.pollFirst(); // 처음 1번 풍선 뺌 | ||
| sb.append(idx).append(" "); | ||
|
|
||
| int move = arr[idx - 1]; // idx 0부터 시작 | ||
| if (deque.isEmpty()) break; // deque가 비었으면 그냥 멈춤 | ||
|
|
||
| if (move > 0) { | ||
| for (int i = 0; i < move - 1; i++) { | ||
| deque.offerLast(deque.pollFirst()); // 맨앞에꺼 빼서 맨뒤로 보냄 - 왼쪽 회전 | ||
| } | ||
| } else { | ||
| for (int j = 0; j < Math.abs(move); j++) { | ||
| deque.offerFirst(deque.pollLast()); // 맨뒤에꺼 빼서 앞으로 보냄 - 오른쪽 회전 | ||
| } | ||
| } | ||
| } | ||
|
|
||
| System.out.println(sb.toString().trim()); | ||
| } | ||
| } | ||
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.
잔인한 메서드명 ...