-
Notifications
You must be signed in to change notification settings - Fork 0
Min: 2월 1주차 문제 풀이 #14
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
Merged
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
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,40 @@ | ||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.StringTokenizer; | ||
|
|
||
| class Min { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| int N = Integer.parseInt(br.readLine()); | ||
| List<int[]> list = new ArrayList<>(); | ||
| for(int i = 0; i < N; i++) { | ||
| StringTokenizer str = new StringTokenizer(br.readLine()); | ||
| int c = Integer.parseInt(str.nextToken()); | ||
| int stu = Integer.parseInt(str.nextToken()); | ||
| int score = Integer.parseInt(str.nextToken()); | ||
|
|
||
| list.add(new int[]{c, stu, score}); | ||
| } | ||
|
|
||
| list.sort((a, b) -> b[2]- a[2]); | ||
| int[] countryCnt = new int[101]; | ||
| int cnt = 0; | ||
| StringBuilder sb = new StringBuilder(); | ||
|
|
||
| for(int i = 0; i < list.size(); i++) { | ||
| if(cnt == 3) break; | ||
| int[] cur = list.get(i); | ||
| int countryIdx = cur[0]; | ||
| if(countryCnt[countryIdx] < 2) { | ||
| sb.append(cur[0]).append(" ").append(cur[1]).append("\n"); | ||
| countryCnt[countryIdx] += 1; | ||
| cnt += 1; | ||
| } | ||
| } | ||
|
|
||
| System.out.println(sb); | ||
| } | ||
| } |
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,35 @@ | ||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| public class Min { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| int N = Integer.parseInt(br.readLine()); | ||
| List<Integer> list = new ArrayList<>(); | ||
| for(int i = 0; i < N; i++) { | ||
| list.add(Integer.parseInt(br.readLine())); | ||
| } | ||
|
|
||
| Collections.sort(list); | ||
| int answer = 4; | ||
| for(int i = 0; i < list.size(); i++) { | ||
| int num = list.get(i); | ||
| int need = 4; | ||
| for(int j = 0; j < 4; j++) { | ||
| if(list.contains(++num)) { | ||
| need -= 1; | ||
| } | ||
| } | ||
|
|
||
| answer = Math.min(answer, need); | ||
| } | ||
|
|
||
| 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,85 @@ | ||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.util.StringTokenizer; | ||
|
|
||
| public class Min { | ||
| static String[][] wheels; | ||
| static int[] rotate; | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| wheels = new String[4][8]; | ||
| for(int i = 0; i < 4; i++) { | ||
| wheels[i] = br.readLine().split(""); | ||
| } | ||
|
|
||
| int K = Integer.parseInt(br.readLine()); | ||
| for(int i = 0; i < K; i++) { | ||
| StringTokenizer str = new StringTokenizer(br.readLine()); | ||
| int wheel = Integer.parseInt(str.nextToken()) - 1; | ||
| int dir = Integer.parseInt(str.nextToken()); | ||
| rotate = new int[4]; | ||
| rotate[wheel] = dir; | ||
|
|
||
| changeLeft(wheel, dir); | ||
| changeRight(wheel, dir); | ||
|
|
||
| for(int j = 0; j < 4; j++) { | ||
| if(rotate[j] == 1) { | ||
| rotateRight(j); | ||
| } else if(rotate[j] == -1){ | ||
| rotateLeft(j); | ||
| } | ||
| } | ||
| } | ||
| int score = getScore(); | ||
| System.out.println(score); | ||
| } | ||
|
|
||
| private static void rotateRight(int idx) { | ||
| String tmp = wheels[idx][7]; | ||
| for(int i = 7; i > 0; i--) { | ||
| wheels[idx][i] = wheels[idx][i - 1]; | ||
| } | ||
| wheels[idx][0] = tmp; | ||
| } | ||
|
|
||
| private static void rotateLeft(int idx) { | ||
| String tmp = wheels[idx][0]; | ||
| for(int i = 0; i < 7; i++) { | ||
| wheels[idx][i] = wheels[idx][i + 1]; | ||
| } | ||
| wheels[idx][7] = tmp; | ||
| } | ||
|
|
||
| private static void changeLeft(int idx, int dir) { | ||
| if(idx == 0) return; | ||
| if(!wheels[idx][6].equals(wheels[idx - 1][2])) { | ||
| rotate[idx - 1] = -dir; | ||
| changeLeft(idx - 1, -dir); | ||
| } | ||
| } | ||
|
|
||
| private static void changeRight(int idx, int dir) { | ||
| if(idx == 3) return; | ||
| if(!wheels[idx][2].equals(wheels[idx + 1][6])) { | ||
| rotate[idx + 1] = -dir; | ||
| changeRight(idx + 1, -dir); | ||
| } | ||
| } | ||
|
|
||
| private static int getScore() { | ||
| int sum = 0; | ||
| int plus = 1; | ||
| for(int i = 0; i < 4; i++) { | ||
| if(wheels[i][0].equals("1")) { | ||
| sum += plus; | ||
| } | ||
| plus *= 2; | ||
|
Member
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. 이렇게 점수 규칙을 파악해서 배열 생성 없이도 잘 계산할 수 있었네요! 👍 |
||
| } | ||
|
|
||
| return sum; | ||
| } | ||
|
|
||
|
|
||
| } | ||
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.
이렇게 변수 앞에 - 만 붙여도 변환이 가능했네요! 배워갑니다! 👍