Skip to content
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

[241122] BOJ 1283 단축키 지정 #1017

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions sjhlko/week44/BOJ_1283/ShortCut.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package sjhlko.week44.BOJ_1283;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class ShortCut {
//https://www.acmicpc.net/problem/1283
//단축키 지정
static Set<Character> keys = new HashSet<>();

static char changeCase(char c) {
if (c >= 'a' && c <= 'z') return (char) (c - 32);
return (char) (c + 32);
}

static String solution(String[] options) {
boolean flag = false;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < options.length; i++) {
String option = options[i];
if (!flag && !keys.contains(option.charAt(0))) {
keys.add(option.charAt(0));
keys.add(changeCase(option.charAt(0)));
sb.append('[')
.append(option.charAt(0))
.append(']');
sb.append(option.substring(1));
sb.append(" ");
flag = true;
continue;
}
sb.append(option)
.append(" ");
}
if(flag) return sb.toString();


sb = new StringBuilder();
flag = false;
for (int i = 0; i < options.length; i++) {
for (int j = 0; j < options[i].length(); j++) {
if (!flag && !keys.contains(options[i].charAt(j))) {
keys.add(options[i].charAt(j));
keys.add(changeCase(options[i].charAt(j)));
sb.append('[')
.append(options[i].charAt(j))
.append(']');
flag = true;
continue;
}
sb.append(options[i].charAt(j));
}
sb.append(" ");
}
return sb.toString();
}

public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(bf.readLine());
StringBuilder sb = new StringBuilder();
while (N-- > 0) {
String[] options = bf.readLine()
.split(" ");
sb.append(solution(options))
.append("\n");
}
System.out.println(sb);
}
}