-
Notifications
You must be signed in to change notification settings - Fork 26
초급반 / 나의찬 / 단어뒤집기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 all commits
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); | ||
} | ||
} |
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 implementation.파일정리.Uechann; | ||
/* | ||
|
||
문제 | ||
파일들을 잘 분석해서 보물의 주인공이 될 수 있길 바랄게. 힌트는 “확장자”야. | ||
|
||
파일을 확장자 별로 정리해서 몇 개씩 있는지 알려줘 | ||
보기 편하게 확장자들을 사전 순으로 정렬해 줘 | ||
그럼 보물의 절반을 얻어내기 위해 얼른 스브러스의 노트북 파일 정리를 해줄 프로그램을 만들자! | ||
|
||
입력 | ||
첫째 줄에 바탕화면에 있는 파일의 개수 | ||
N이 주어진다. (1 <= N <= 50,000) | ||
|
||
둘째 줄부터 | ||
N개 줄에 바탕화면에 있는 파일의 이름이 주어진다. 파일의 이름은 알파벳 소문자와 점(.)으로만 구성되어 있다. | ||
점은 정확히 한 번 등장하며, 파일 이름의 첫 글자 또는 마지막 글자로 오지 않는다. 각 파일의 이름의 길이는 최소3, 최대 100이다. | ||
|
||
출력 | ||
확장자의 이름과 그 확장자 파일의 개수를 한 줄에 하나씩 출력한다. 확장자가 여러 개 있는 경우 확장자 이름의 사전순으로 출력한다. | ||
*/ | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class Main { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringBuilder sb = new StringBuilder(); | ||
StringTokenizer st; | ||
Map<String, Integer> result = new TreeMap<>(); // 확장자와 개수를 저장할 TreeMap | ||
|
||
int N = Integer.parseInt(br.readLine()); | ||
|
||
for (int i = 0; i < N; i++) { | ||
st = new StringTokenizer(br.readLine(), "."); | ||
// 파일 이름에서 확장자 추출 | ||
String fileName = st.nextToken(); | ||
String extension = st.nextToken(); | ||
result.put(extension, result.getOrDefault(extension, 0) + 1); | ||
} | ||
|
||
// 확장자와 개수를 출력 | ||
for (Map.Entry<String, Integer> entry : result.entrySet()) { | ||
sb.append(entry.getKey()).append(" ").append(entry.getValue()).append("\n"); | ||
} | ||
|
||
System.out.print(sb); | ||
} | ||
} |
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,76 @@ | ||
package simulation.ZOAC3.Uechann; | ||
|
||
/*문제 | ||
독수리 타법이란 양 손의 검지손가락만을 이용해 타자를 치는 타법이다. | ||
성우는 한글 자음 쪽 자판은 왼손 검지손가락으로 입력하고, 한글 모음 쪽 자판은 오른손 검지손가락으로 입력한다. | ||
a의 좌표가 (x1, y1)이고, b의 좌표가 (x2, y2)일 때, a에 위치한 성우의 손가락이 b로 이동하는 데에는 a와 b의 택시 거리 |x1-x2|+|y1-y2| 만큼의 시간이 걸린다. | ||
각 키를 누르는 데에는 1의 시간이 걸린다. | ||
성우는 두 손을 동시에 움직일 수 없다. | ||
성우가 사용하는 키보드는 쿼티식 키보드이며, 아래 그림처럼 생겼다. | ||
|
||
바쁜 성우를 위하여 해당 문자열을 출력하는 데 걸리는 시간의 최솟값을 구해보자. | ||
|
||
입력 | ||
첫 번째 줄에는 두 알파벳 소문자 sL, sR이 주어진다. sL, sR은 각각 왼손 검지손가락, 오른손 검지손가락의 처음 위치이다. | ||
그 다음 줄에는 알파벳 소문자로 구성된 문자열이 주어진다. 문자열의 길이는 최대 100자이다. 빈 문자열은 주어지지 않는다. | ||
|
||
출력 | ||
입력으로 주어진 문자열을 출력하는 데에 걸리는 시간의 최솟값을 출력한다.*/ | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
import java.util.StringTokenizer; | ||
|
||
public class Main { | ||
public static void main(String[] args) throws IOException { | ||
char[][] keyboard = { | ||
{'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'}, | ||
{'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'}, | ||
{'z', 'x', 'c', 'v', 'b', 'n', 'm'} | ||
}; | ||
|
||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st; | ||
|
||
st = new StringTokenizer(br.readLine()); | ||
char sl = st.nextToken().charAt(0); // 왼손 검지손가락의 초기 위치 | ||
char sr = st.nextToken().charAt(0); // 오른손 검지손가락의 초기 위치 | ||
|
||
String input = br.readLine(); // 입력 문자열 | ||
|
||
int time = 0; // 총 시간 초기화 | ||
|
||
for (char c : input.toCharArray()) { | ||
int[] leftPos = findPosition(keyboard, sl); | ||
int[] rightPos = findPosition(keyboard, sr); | ||
int[] targetPos = findPosition(keyboard, c); | ||
|
||
// 모음일 경우 오른손 사용 | ||
if (targetPos[1] >= 5 || Arrays.equals(targetPos, new int[]{2, 4})) { | ||
int rightTime = Math.abs(rightPos[0] - targetPos[0]) + Math.abs(rightPos[1] - targetPos[1]); | ||
sr = c; // 오른손 위치 업데이트 | ||
time += rightTime + 1;// 오른손 이동 시간 + 1 (키 누르는 시간) | ||
} | ||
else{//자음일 경우 왼손 사용 | ||
int leftTime = Math.abs(leftPos[0] - targetPos[0]) + Math.abs(leftPos[1] - targetPos[1]); | ||
time += leftTime + 1;// 왼손 이동 시간 + 1 (키 누르는 시간) | ||
sl = c; // 왼손 위치 업데이트 | ||
} | ||
} | ||
|
||
System.out.println(time); // 총 시간 출력 | ||
} | ||
|
||
private static int[] findPosition(char[][] keyboard, char c) { | ||
for (int i = 0; i < keyboard.length; i++) { | ||
for (int j = 0; j < keyboard[i].length; j++) { | ||
if (keyboard[i][j] == c) { | ||
return new int[]{i, j}; // 행, 열 반환 | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
} |
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줄이 선택되었네요 .. ! ㅠㅠ)