-
Notifications
You must be signed in to change notification settings - Fork 1
0401프로그래머스 #33
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
platycodonv
wants to merge
1
commit into
main
Choose a base branch
from
origin/platycodonv_0401
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
0401프로그래머스 #33
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,54 @@ | ||
| package A0331; | ||
|
|
||
| import java.util.StringTokenizer; | ||
|
|
||
| public class Solution { | ||
|
|
||
| public static void main(String[] args) { | ||
| String[] id_list= {"con", "ryan"}; | ||
| String[] report = {"ryan con", "ryan con", "ryan con", "ryan con"}; | ||
| int[][] check = new int[id_list.length][id_list.length]; | ||
| int k = 3; | ||
| int[] stop = new int[id_list.length]; | ||
| int[] answer = new int[id_list.length]; | ||
|
|
||
| for(int i = 0;i<report.length;i++) { | ||
| StringTokenizer st = new StringTokenizer(report[i]," "); | ||
| String one = st.nextToken(); | ||
| String two = st.nextToken(); | ||
| //System.out.println(one+ " "+two); | ||
| int police = 0; //신고한사람 idx | ||
| int thief = 0; //신고 당한사람 idx | ||
| for (int j = 0; j < id_list.length; j++) { | ||
| if(id_list[j].equals(one)) police = j; | ||
| if(id_list[j].equals(two)) thief = j; | ||
| } | ||
| check[police][thief] = 1; | ||
| } | ||
|
|
||
| for(int i = 0;i< id_list.length;i++) { | ||
| for(int j = 0;j< id_list.length;j++) { | ||
| if(check[j][i] == 1) stop[i] ++; | ||
| } | ||
| } | ||
| /*for(int i =0;i<stop.length;i++) { | ||
| System.out.print(stop[i]+" "); | ||
| } | ||
|
|
||
| System.out.println("");*/ | ||
|
|
||
|
|
||
| for(int i = 0;i<id_list.length;i++) { | ||
| for(int j = 0;j<id_list.length;j++) { | ||
| if(stop[j] >= k && check[i][j] == 1) { | ||
| answer[i]++; | ||
| } | ||
| } | ||
| } | ||
| /*for(int i =0;i<stop.length;i++) { | ||
| System.out.print(answer[i]+" "); | ||
| }*/ | ||
|
|
||
| } | ||
|
|
||
| } |
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,50 @@ | ||
| package A0331; | ||
|
|
||
| import java.util.*; | ||
| import java.io.*; | ||
|
|
||
| public class Solution2 { | ||
|
|
||
|
|
||
| public static void main(String[] args) throws Exception{ | ||
| int n = 1000000; | ||
| int k = 3; | ||
| String change=""; | ||
| int answer = 0; | ||
| //진법변환 | ||
|
|
||
| change = Integer.toString(n, k); | ||
| // change = ""; | ||
| change += '0'; | ||
|
|
||
| String sector = ""; | ||
| for(int i = 0; i<change.length();i++) { | ||
| if(change.charAt(i) != '0') sector += change.charAt(i); | ||
| else { | ||
| //Integer.parseInt(sector); | ||
| //System.out.println(sector); | ||
| int temp = Integer.parseInt(sector); | ||
| //System.out.println(temp); | ||
| sector = "0"; //null 대신에 이걸 넣어줘야함 | ||
| if(isPrime(temp)) { | ||
| answer ++; | ||
| } | ||
| else continue; | ||
| } | ||
| } | ||
| System.out.println(answer); | ||
|
|
||
| } | ||
| static boolean isPrime(long number) { | ||
|
|
||
| if(number == 0) return false; | ||
| if(number == 1) return false; | ||
| if(number == 2) return true; | ||
| for(int i = 3; i<=Math.sqrt(number); i = i+2) { | ||
|
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. 매우 좋은 코드였습니다. 감사합니다 !
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. for문이 반복할 때마다 조건문을 확인하기 때문에, 매번 Math.sqrt() 함수가 실행됩니다 |
||
| if(number % i == 0) return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
|
|
||
| } | ||
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.
String에 + 연산이 많아질거 같은 경우에는 StringBuilder를 사용하는 것을 권장합니다 !

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.
좋아용~