-
Notifications
You must be signed in to change notification settings - Fork 0
[Week05] 덱 / 박나현 #24
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
nahyuunn
wants to merge
3
commits into
main
Choose a base branch
from
nahyuunn
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] 덱 / 박나현 #24
Changes from all commits
Commits
Show all changes
3 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
44 changes: 44 additions & 0 deletions
44
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,44 @@ | ||
| package week05.boj13417; | ||
|
|
||
| import java.util.*; | ||
| import java.io.*; | ||
|
|
||
| public class 카드문자열_박나현 { | ||
| public static void main(String[] args) throws IOException { | ||
| StringBuilder sb = new StringBuilder(); | ||
|
|
||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
|
||
|
|
||
| int count = Integer.parseInt(st.nextToken()); | ||
|
|
||
| while (count-- > 0) { | ||
|
|
||
| Deque<String> deq = new ArrayDeque<>(); | ||
|
|
||
| st = new StringTokenizer(br.readLine()); | ||
| int length = Integer.parseInt(st.nextToken()); | ||
|
|
||
| st = new StringTokenizer(br.readLine()); | ||
|
|
||
| while (length-- > 0) { | ||
| String c = st.nextToken(); | ||
| if (deq.isEmpty()) { | ||
| deq.offer(c); | ||
| } else { | ||
| if (c.compareTo(deq.peekFirst()) > 0) { | ||
| deq.offerLast(c); | ||
| } else deq.offerFirst(c); | ||
| } | ||
| } | ||
|
|
||
| while (!deq.isEmpty()) { | ||
| sb.append(deq.poll()); | ||
| } | ||
|
|
||
| sb.append("\n"); | ||
| } | ||
| System.out.println(sb); | ||
| } | ||
| } | ||
53 changes: 53 additions & 0 deletions
53
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,53 @@ | ||
| package week05.boj20301; | ||
|
|
||
| import java.io.*; | ||
| import java.util.*; | ||
|
|
||
| public class 반전요세푸스_박나현 { | ||
| static Deque<Integer> deq = new ArrayDeque<>(); | ||
| static StringBuilder sb = new StringBuilder(); | ||
| static int count = 0; | ||
| static boolean turn = false; | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
|
||
| int n = Integer.parseInt(st.nextToken()); | ||
| int k = Integer.parseInt(st.nextToken()); | ||
| int m = Integer.parseInt(st.nextToken()); | ||
|
|
||
| for (int i = 1; i <= n; i++) { | ||
| deq.offerLast(i); | ||
| } | ||
|
|
||
| while (!deq.isEmpty()) { | ||
| if (!turn) { | ||
| turnRight(k); | ||
| } else { | ||
| turnLeft(k); | ||
| } | ||
|
|
||
| count++; | ||
| if (count == m) { | ||
| count = 0; | ||
|
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. 저는 배수로 판별하는 방법 밖에 생각 못 했는데 내부에서 다시 초기화 해주는 방법도 있군요!! 배워갑니다 :) |
||
| turn = !turn; | ||
| } | ||
| } | ||
| System.out.println(sb); | ||
| } | ||
|
|
||
| private static void turnRight(int k) { | ||
| for (int i = 0; i < k-1; i++) { | ||
| deq.offerLast(deq.pollFirst()); | ||
| } | ||
| sb.append(deq.pollFirst()).append("\n"); | ||
| } | ||
|
|
||
| private static void turnLeft(int k) { | ||
| for (int i = 0; i < k-1; i++) { | ||
| deq.offerFirst(deq.pollLast()); | ||
| } | ||
| sb.append(deq.pollLast()).append("\n"); | ||
| } | ||
| } | ||
47 changes: 47 additions & 0 deletions
47
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,47 @@ | ||
| package week05.boj2346; | ||
|
|
||
| import java.util.*; | ||
| import java.io.*; | ||
|
|
||
| // 메모리: 15564KB | 시간: 164ms | ||
| public class 풍선터뜨리기_박나현 { | ||
| public static void main(String[] args) throws IOException { | ||
|
|
||
| StringBuilder sb = new StringBuilder(); | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
|
||
| // index 구하는 메서드가 없어 배열로 저장 | ||
| Deque<int[]> deq = new ArrayDeque<>(); | ||
|
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. 덱을 배열로 넣어서 푸신 아이디어가 신박하네요 ..! |
||
|
|
||
| // size 만큼 deq에 값 저장 | ||
| int size = Integer.parseInt(br.readLine()); | ||
|
|
||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
| for (int i = 1; i <= size; i++) { | ||
| int n = Integer.parseInt(st.nextToken()); | ||
| deq.offer(new int[]{i, n}); | ||
| } | ||
|
|
||
| int[] first = deq.pollFirst(); | ||
| sb.append(first[0]).append(" "); | ||
|
|
||
| int next = first[1]; | ||
|
|
||
| while (!deq.isEmpty()) { | ||
| if (next > 0) { | ||
| for (int j = 0; j < next-1; j++) { | ||
| deq.offerLast(deq.poll()); | ||
| } | ||
| } else { | ||
| for (int j = 0; j < Math.abs(next); j++) { | ||
| deq.offerFirst(deq.pollLast()); | ||
| } | ||
| } | ||
|
|
||
| first = deq.poll(); | ||
| sb.append(first[0]).append(" "); | ||
| next = first[1]; | ||
| } | ||
| System.out.println(sb); | ||
| } | ||
| } | ||
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.
여기까지 작성한 뒤에 continue (아마 break 아니고 continue일 것 같은데 잘못됐다면 죄송합니다 ㅜㅜ) 로 끊어주면
조건문 중첩이 줄어서 가독성이 더 좋아질 것 같습니다..!