-
Notifications
You must be signed in to change notification settings - Fork 40
[아리] 8주차 문제 제출 #244
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
ulimy
wants to merge
6
commits into
woowacourse-study:main
Choose a base branch
from
ulimy:main
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주차 문제 제출 #244
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
aaa64a1
14938 서강그라운드
ulimy 7915e12
24393 조커 찾기
ulimy 2619e2c
Merge branch 'main' of https://github.com/woowacourse-study/2022-lv3-…
ulimy b4c344c
24499 blobyum
ulimy 9847cfc
14906 스러피
ulimy 9357665
Merge branch 'main' of https://github.com/ulimy/2022-lv3-algorithm-study
ulimy 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,70 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.regex.Pattern; | ||
|
||
public class Main { | ||
|
||
private static final Pattern slumpPattern = Pattern.compile("^((D|E)(F)+)+(G)$"); | ||
private static final Pattern slimpPatternABC = Pattern.compile("(AB)\\w+(C)$"); | ||
private static final Pattern slimpPatternAC = Pattern.compile("(A)\\w+(C)$"); | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
int count = Integer.parseInt(br.readLine()); | ||
|
||
StringBuilder result = new StringBuilder("SLURPYS OUTPUT\n"); | ||
|
||
while (count-- > 0) { | ||
String input = br.readLine(); | ||
boolean isSlurpy = false; | ||
|
||
// 스림프의 길이는 2 이상이니 2부터 | ||
for (int i = 2; i <= input.length() - 3; i++) { | ||
String slimp = input.substring(0, i); | ||
String slump = input.substring(i); | ||
|
||
// 찾았다면 바로 끝~~ | ||
if (isSlimp(slimp) && isSlump(slump)) { | ||
isSlurpy = true; | ||
break; | ||
} | ||
|
||
} | ||
|
||
result.append(isSlurpy ? "YES\n" : "NO\n"); | ||
|
||
} | ||
|
||
result.append("END OF OUTPUT"); | ||
|
||
System.out.println(result); | ||
|
||
} | ||
|
||
private static boolean isSlump(String input) { | ||
return slumpPattern.matcher(input).matches(); | ||
} | ||
|
||
private static boolean isSlimp(String input) { | ||
|
||
if (input.length() > 3) { | ||
|
||
// AB - C라면 가운데 스림프인지 확인 | ||
if (slimpPatternABC.matcher(input).matches()) { | ||
return isSlimp(input.substring(2, input.length() - 1)); | ||
} | ||
|
||
// A - C 라면 가운데 스림프인지 확인 | ||
else if (slimpPatternAC.matcher(input).matches()) { | ||
return isSlump(input.substring(1, input.length() - 1)); | ||
} | ||
|
||
} else { | ||
return input.equals("AH"); | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
|
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.
개인적으로 궁금한건데
slumpPattern
에서(F)+
가 아니고F+
라고 하면 의도대로 작동이 안되나요?언제 그룹화를 해야 되고, 언제 안해야되는지 헷갈려서요!