forked from c4fiber/java-onboarding
-
Notifications
You must be signed in to change notification settings - Fork 5
[java-onboarding-week-1] roki.kim(김경록) 과제 제출합니다. #1
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
KimGyeongLock
wants to merge
15
commits into
Japring-Study:roki/java-onboarding-week-1
Choose a base branch
from
KimGyeongLock:roki/java-onboarding-week-1
base: roki/java-onboarding-week-1
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
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
34ed3f3
문제 1 해결
KimGyeongLock a11e2e7
문제 2 해결
KimGyeongLock b14b253
문제 3 해결
KimGyeongLock 1eb140e
문제 4 해결
KimGyeongLock 6c8e2ba
문제 5 해결
KimGyeongLock 4e66704
문제 6 해결
KimGyeongLock cb16b8e
문제 7 해결
KimGyeongLock 4d345d1
문제 1 예외처리 추가, test code 추가
KimGyeongLock b0538de
문제 2 연속된 2개 이상의 문자 처리, 제한사항 예외처리
KimGyeongLock c39fef8
문제 3 제한사항 예외처리
KimGyeongLock 1512a2a
문제 4 제한사항 예외처리
KimGyeongLock 0719476
문제 5 제한사항 예외처리
KimGyeongLock f7dc102
문제 6 제한사항 예외처리
KimGyeongLock aaffd2c
문제 7 제한사항 예외처리, 네이밍, 코드 리팩토링
KimGyeongLock 0a79b6c
코드 리뷰 피드백 전부 반영
KimGyeongLock 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 |
|---|---|---|
| @@ -1,10 +1,88 @@ | ||
| package onboarding; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| class Problem1 { | ||
| public static int solution(List<Integer> pobi, List<Integer> crong) { | ||
| int answer = Integer.MAX_VALUE; | ||
| int answer = 0; | ||
|
|
||
| // 예외 처리 함수 호출 | ||
| if (!isValidInput(pobi) || !isValidInput(crong)) { | ||
| return -1; | ||
| } | ||
|
|
||
| int pobiMaxScore = calculateMaxPageScore(pobi); | ||
| int crongMaxScore = calculateMaxPageScore(crong); | ||
| if (pobiMaxScore > crongMaxScore) return 1; | ||
| else if (pobiMaxScore < crongMaxScore) return 2; | ||
|
|
||
| return answer; | ||
| } | ||
| } | ||
|
|
||
| // 예외 처리 함수 | ||
| public static boolean isValidInput(List<Integer> pages) { | ||
| if (pages.size() != 2) { | ||
| return false; | ||
| } | ||
| int leftPage = pages.get(0); | ||
| int rightPage = pages.get(1); | ||
|
|
||
| // 페이지 번호가 범위를 벗어나는 경우 | ||
| if (leftPage <= 1 || rightPage >= 400) { | ||
| return false; | ||
| } | ||
|
|
||
| // 페이지 순서가 잘못되었거나 차이가 1이 아닌 경우 | ||
| if (rightPage <= leftPage || rightPage - leftPage != 1) { | ||
| return false; | ||
| } | ||
|
|
||
| // 왼쪽 페이지는 홀수, 오른쪽 페이지는 짝수이어야 함 | ||
| if (leftPage % 2 != 1 || rightPage % 2 != 0) { | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| public static List<Integer> splitDigits(int number) { | ||
| List<Integer> result = new ArrayList<>(); | ||
|
|
||
| while (number > 0) { | ||
| result.add(0, number % 10); | ||
| number = number / 10; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| public static Integer sumDigits(List<Integer> digits) { | ||
| int sum = 0; | ||
| for (int digit : digits) { | ||
| sum += digit; | ||
| } | ||
| return sum; | ||
| } | ||
|
|
||
| public static Integer multiplyDigits(List<Integer> digits) { | ||
| int product = 1; | ||
| for (int digit : digits) { | ||
| product *= digit; | ||
| } | ||
| return product; | ||
| } | ||
|
|
||
| public static Integer calculateMaxSumOrProduct(Integer page) { | ||
| List<Integer> pageDigits = splitDigits(page); | ||
| int sumOfDigits = sumDigits(pageDigits); | ||
| int productOfDigits = multiplyDigits(pageDigits); | ||
| return Math.max(sumOfDigits, productOfDigits); | ||
| } | ||
|
|
||
| public static Integer calculateMaxPageScore(List<Integer> user) { | ||
| int maxLeftPageScore = calculateMaxSumOrProduct(user.get(0)); | ||
| int maxRightPageScore = calculateMaxSumOrProduct(user.get(1)); | ||
|
|
||
| return Math.max(maxLeftPageScore, maxRightPageScore); | ||
| } | ||
| } |
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
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 |
|---|---|---|
| @@ -1,8 +1,26 @@ | ||
| package onboarding; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| public class Problem3 { | ||
| public static int solution(int number) { | ||
| int answer = 0; | ||
| if(number < 1 || number > 10000) { | ||
| return -1; | ||
| } | ||
|
|
||
| List<Integer> clapNumbers = Arrays.asList(3, 6, 9); | ||
|
|
||
| for(int i = 1; i <= number; i++) { | ||
| List<Integer> digits = Problem1.splitDigits(i); | ||
| for (Integer digit : digits) { | ||
| if (clapNumbers.contains(digit)) { | ||
| answer++; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| 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 |
|---|---|---|
| @@ -1,8 +1,36 @@ | ||
| package onboarding; | ||
|
|
||
| public class Problem4 { | ||
|
|
||
| private static final int LOWERCASE_TRANSFORM_BASE = 219; | ||
| private static final int UPPERCASE_TRANSFORM_BASE = 155; | ||
|
|
||
| public static String solution(String word) { | ||
| String answer = ""; | ||
|
|
||
| if(word.length() < 1 || word.length() > 1000) { | ||
| return "error"; | ||
| } | ||
|
|
||
| for(int i = 0; i < word.length(); i++) { | ||
| char c = word.charAt(i); | ||
|
|
||
| if(c == ' ') { | ||
| answer += ' '; | ||
| continue; | ||
| } | ||
|
|
||
| char newChar; | ||
| if(c >= 'a' && c <= 'z') { //소문자 | ||
| newChar = (char) (LOWERCASE_TRANSFORM_BASE - c); | ||
| } else if (c >= 'A' && c <= 'Z') { // 대문자 변환 | ||
| newChar = (char) (UPPERCASE_TRANSFORM_BASE - c); | ||
| } else { | ||
| newChar = c; // 알파벳이 아닌 경우 그대로 유지 | ||
| } | ||
| answer += newChar; | ||
| } | ||
|
|
||
| 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 |
|---|---|---|
| @@ -1,11 +1,33 @@ | ||
| package onboarding; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| public class Problem5 { | ||
| public static List<Integer> solution(int money) { | ||
| List<Integer> answer = Collections.emptyList(); | ||
|
|
||
| if (money < 1 || money > 1000000) { | ||
| return null; | ||
| } | ||
|
|
||
| List<Integer> answer = new ArrayList<>(); | ||
| final List<Integer> moneyUnit = List.of( | ||
| 50000, | ||
| 10000, | ||
| 5000, | ||
| 1000, | ||
| 500, | ||
| 100, | ||
| 50, | ||
| 10, | ||
| 1 | ||
| ); | ||
|
|
||
| for (int i = 0; i < moneyUnit.size(); i++) { | ||
| answer.add(money / moneyUnit.get(i)); | ||
| money = money % moneyUnit.get(i); | ||
| } | ||
| 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 |
|---|---|---|
| @@ -1,10 +1,72 @@ | ||
| package onboarding; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
|
|
||
| public class Problem6 { | ||
| public static List<String> solution(List<List<String>> forms) { | ||
| List<String> answer = List.of("answer"); | ||
| List<String> answer = new ArrayList<>(); | ||
| if (forms.size() < 1 || forms.size() > 10000) { | ||
| return null; | ||
| } | ||
|
|
||
| for (int i = 0; i < forms.size(); i++) { | ||
| String email = forms.get(i).get(0); | ||
| String name = forms.get(i).get(1); | ||
|
|
||
| if (!isValidEmail(email) || !isValidNickname(name) || answer.contains(email)) { | ||
| continue; | ||
| } | ||
|
|
||
| checkDuplicateSubstrings(forms, i, name, email, answer); | ||
| } | ||
|
|
||
| answer.sort(Comparator.naturalOrder()); | ||
| return answer; | ||
| } | ||
| } | ||
|
|
||
| private static void checkDuplicateSubstrings(List<List<String>> forms, int currentIndex, String currentName, String currentEmail, List<String> answer) { | ||
| for (int j = currentIndex + 1; j < forms.size(); j++) { | ||
| String compName = forms.get(j).get(1); | ||
| String compEmail = forms.get(j).get(0); | ||
|
|
||
| if (answer.contains(compEmail)) { | ||
| continue; | ||
| } | ||
|
|
||
| if (hasDuplicateSubstring(currentName, compName)) { | ||
| answer.add(compEmail); | ||
| if (!answer.contains(currentEmail)) { | ||
| answer.add(currentEmail); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static boolean hasDuplicateSubstring(String name1, String name2) { | ||
| for (int k = 0; k < name2.length() - 1; k++) { | ||
| String subString = name2.substring(k, k + 2); | ||
| if (name1.contains(subString)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private static boolean isValidEmail(String email) { | ||
| if (email.length() < 11 || email.length() >= 20) { | ||
| return false; | ||
| } | ||
| String emailPattern = "^[a-zA-Z0-9._%+-]+@email\\.com$"; | ||
| return email.matches(emailPattern); | ||
| } | ||
|
|
||
| private static boolean isValidNickname(String name) { | ||
| if (name.length() < 1 || name.length() >= 20) { | ||
| return false; | ||
| } | ||
| String nicknamePattern = "^[가-힣]+$"; | ||
| return name.matches(nicknamePattern); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
함수를 작은 단위로 분리하면 더 보기 좋을 것 같아요!
3중 for문이라 너무 깊어지는 거 같아요