-
Notifications
You must be signed in to change notification settings - Fork 23
초급반 / 나의찬 / 단어뒤집기2-17413, 파일정리-20291, ZOAC-30436 #105
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
Uechann
wants to merge
3
commits into
Alom-codingTest:main
Choose a base branch
from
Uechann: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
Changes from 1 commit
Commits
Show all changes
3 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,78 @@ | ||
| package implementation.단어뒤집기2.Uechann; | ||
|
|
||
| /*문제 | ||
| 문자열 S가 주어졌을 때, 이 문자열에서 단어만 뒤집으려고 한다. | ||
|
|
||
| 먼저, 문자열 S는 아래와과 같은 규칙을 지킨다. | ||
|
|
||
| 알파벳 소문자('a'-'z'), 숫자('0'-'9'), 공백(' '), 특수 문자('<', '>')로만 이루어져 있다. | ||
| 문자열의 시작과 끝은 공백이 아니다. | ||
| '<'와 '>'가 문자열에 있는 경우 번갈아가면서 등장하며, '<'이 먼저 등장한다. 또, 두 문자의 개수는 같다. | ||
| 태그는 '<'로 시작해서 '>'로 끝나는 길이가 3 이상인 부분 문자열이고, '<'와 '>' 사이에는 알파벳 소문자와 공백만 있다. | ||
| 단어는 알파벳 소문자와 숫자로 이루어진 부분 문자열이고, | ||
| 연속하는 두 단어는 공백 하나로 구분한다. 태그는 단어가 아니며, 태그와 단어 사이에는 공백이 없다. | ||
|
|
||
| 입력 | ||
| 첫째 줄에 문자열 S가 주어진다. S의 길이는 100,000 이하이다. | ||
|
|
||
| 출력 | ||
| 첫째 줄에 문자열 S의 단어를 뒤집어서 출력한다. | ||
| */ | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.util.Stack; | ||
|
|
||
| // 1H | ||
| public class Main { | ||
| public static void main(String[] args) throws IOException { | ||
| //스택 사용! | ||
| Stack<Character> stack = new Stack<>(); | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| StringBuilder sb = new StringBuilder(); | ||
| String input = br.readLine(); | ||
| char[] chars = input.toCharArray(); | ||
|
|
||
| //태그를 처리할 플래그 변수 | ||
| boolean Tag = false; | ||
|
|
||
| //입력 문자열을 한 글자씩 순회 | ||
| for (int i = 0; i < input.length(); i++) { | ||
| char c = chars[i]; | ||
|
|
||
| if (c == '<') { | ||
| //태그 시작 | ||
| Tag = true; | ||
| while (!stack.isEmpty()) { | ||
| sb.append(stack.pop()); | ||
| } | ||
| sb.append("<"); | ||
| } else if (c == '>') { | ||
| //태그 끝 | ||
| Tag = false; | ||
| sb.append(">"); | ||
| } else if (Tag) { | ||
| // 태그 내부 | ||
| sb.append(c); | ||
| } else { | ||
| if( c == ' ') { | ||
| //공백인 경우 | ||
| while (!stack.isEmpty()) { | ||
| sb.append(stack.pop()); | ||
| } | ||
| sb.append(" "); | ||
| } else { | ||
| //단어인 경우 | ||
| stack.push(c); | ||
| } | ||
| } | ||
| } | ||
| //스택에 남아있는 단어를 뒤집어서 추가 | ||
| while (!stack.isEmpty()) { | ||
| sb.append(stack.pop()); | ||
| } | ||
| //결과 출력 | ||
| System.out.println(sb); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
chatAt(i) 를 매번 호출하는 것보다 더 효율적인 방법인 것 같아요!
좋은 최적화인 것 같습니다.
(35번째 줄만 선택하려했는데, 4줄이 선택되었네요 .. ! ㅠㅠ)