-
Notifications
You must be signed in to change notification settings - Fork 40
[연로그] 8주차 과제 제출 #245
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
yeon-06
wants to merge
1
commit into
woowacourse-study:main
Choose a base branch
from
yeon-06:week8
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
[연로그] 8주차 과제 제출 #245
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,68 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
public class Main { | ||
|
||
private static final StringBuilder sb = new StringBuilder(); | ||
|
||
public static void main(String[] args) throws IOException { | ||
// input | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
int n = Integer.parseInt(br.readLine()); | ||
|
||
sb.append("SLURPYS OUTPUT\n"); | ||
for (int i = 0; i < n; i++) { | ||
String string = br.readLine(); | ||
if (isSlurpy(string)) { | ||
sb.append("YES\n"); | ||
} else { | ||
sb.append("NO\n"); | ||
} | ||
} | ||
sb.append("END OF OUTPUT\n"); | ||
System.out.println(sb); | ||
br.close(); | ||
} | ||
|
||
private static boolean isSlurpy(String string) { | ||
int index = string.lastIndexOf('C'); | ||
if (index == -1) { | ||
if (string.startsWith("AH")) { | ||
return isSlump(string.substring(2)); | ||
} | ||
return false; | ||
} | ||
|
||
String checkSlimp = string.substring(0, index + 1); | ||
String checkSlump = string.substring(index + 1); | ||
|
||
return isSlimp(checkSlimp) && isSlump(checkSlump); | ||
} | ||
|
||
private static boolean isSlimp(String string) { | ||
int length = string.length(); | ||
|
||
if (length < 2) { | ||
return false; | ||
} | ||
|
||
if (length == 2) { | ||
return "AH".equals(string); | ||
} | ||
|
||
if (string.charAt(0) != 'A' || string.charAt(length - 1) != 'C') { | ||
return false; | ||
} | ||
|
||
if (string.charAt(1) == 'B') { | ||
return isSlimp(string.substring(2, length - 1)); | ||
} | ||
|
||
return isSlump(string.substring(1, length - 1)); | ||
} | ||
|
||
private static boolean isSlump(String string) { | ||
return string.matches("^[DE]F+[DEFG]*G$"); | ||
} | ||
} |
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,46 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
|
||
public class Main { | ||
|
||
// 3중 for문으로 풀었는데 돌아가는게 맞는걸까요? ........ | ||
// 다른 풀이 방법은 생각 안나서 일단 제출합니다 좋은 풀이 방법에 대한 힌트 제안 부탁드려요 | ||
|
||
public static void main(String[] args) throws IOException { | ||
// input | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
br.readLine(); | ||
int[] as = convert(br.readLine()); | ||
int[] bs = convert(br.readLine()); | ||
int[] cs = convert(br.readLine()); | ||
br.close(); | ||
|
||
// sort | ||
Arrays.sort(as); | ||
Arrays.sort(bs); | ||
Arrays.sort(cs); | ||
|
||
// calculate | ||
int min = Integer.MAX_VALUE; | ||
for (int a : as) { | ||
for (int b : bs) { | ||
for (int c : cs) { | ||
min = Math.min(calculate(a, b, c), min); | ||
} | ||
} | ||
} | ||
Comment on lines
+26
to
+33
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. |
||
System.out.println(min); | ||
} | ||
|
||
private static int[] convert(String string) { | ||
return Arrays.stream(string.split(" ")) | ||
.mapToInt(Integer::parseInt) | ||
.toArray(); | ||
} | ||
|
||
private static int calculate(int a, int b, int c) { | ||
return Math.abs(Math.max(a, Math.max(b, c)) - Math.min(a, Math.min(b, c))); | ||
} | ||
} |
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.
java에서
lastIndexOf
,startsWith
문법 새롭게 알고 갑니다 👍