-
Notifications
You must be signed in to change notification settings - Fork 2
박지우: 퇴사 #64
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
박지우: 퇴사 #64
Changes from all commits
Commits
Show all changes
2 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,26 @@ | ||
| package j2woo.week3; | ||
| import java.util.*; | ||
| public class 가장큰수 { | ||
| class Solution { | ||
| public String solution(int[] numbers) { | ||
| String answer = ""; | ||
| String numString[] =new String[numbers.length]; | ||
| for(int i=0;i<numbers.length;i++){ // numbers int -> String 배열로 변환, 이유는 String으로 정렬하여 큰 수 비교하기 위해 | ||
| numString[i]=Integer.toString(numbers[i]); | ||
| } | ||
| Arrays.sort(numString,new Comparator<>(){ | ||
| // 내림차순 정렬 | ||
| @Override | ||
| public int compare(String o1, String o2){ // string형 배열이면 sort(A)는 UTF-16 문자 인코딩 체계의 코드 순서에 따라 요소를 정렬한다. | ||
| return (o2+o1).compareTo(o1+o2); // {6, 10, 2}-> {6, 2, 10} | ||
| } | ||
| }); | ||
| answer=String.join(answer,numString); // 문자열 배열 이어붙이기 | ||
| // 숫자가 다 0일 때 | ||
| if(numString[0].equals("0")){ | ||
| answer="0"; | ||
| } | ||
| return 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,34 @@ | ||
| package j2woo.week4; | ||
| import java.io.*; | ||
| import java.util.*; | ||
| public class 퇴사 { | ||
| 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()); // 퇴사 전까지 남은 N일 | ||
| // 상담 일정표 plan[i][0]: i일 상담의 걸리는 기간 T, plan[i][1]: i일 상담의 금액 P | ||
| int [][] plan=new int[N+1][2]; // 1일부터 N일까지 확인위해 N+1 | ||
| for(int i=1; i<N+1; i++){ | ||
| st=new StringTokenizer(br.readLine()); | ||
| plan[i][0]=Integer.parseInt(st.nextToken()); | ||
| plan[i][1]=Integer.parseInt(st.nextToken()); | ||
| } | ||
|
|
||
| int D[]=new int[N+2]; // 다이나믹 프로그래밍 사용, i일까지의 최대 수익, N+1일(퇴사까지 비교) | ||
| for(int i=1; i<N+1; i++){ | ||
| int T=plan[i][0]; // i일 상담의 걸리는 시간 | ||
| int P=plan[i][1]; // i일 상담의 금액 | ||
|
|
||
| if(i+plan[i][0]<=N+1){ // 오늘 상담이 퇴사 전까지 끝나는지 확인 | ||
| // i일의 상담을 들었을 때 | ||
| // D[i+T]=D[i+T]와 오늘까지의 최대값 D[i]+P 비교해서 큰 값 넣어주기 | ||
| D[i+T]=Math.max(D[i+T],D[i]+P); | ||
| } | ||
| // i+1날의 값에 i+1날의 최대 수익과 오늘까지의 최대 수익 비교해서 넣어주기 | ||
| D[i+1]=Math.max(D[i+1],D[i]); | ||
| } | ||
| // 퇴사날의 최대값 출력! | ||
| System.out.println(D[N+1]); | ||
| } | ||
| } | ||
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.
저는 이 부분이 와닿지 않아서 해결못했었는데, 주석보니 이해가 되네용