• 문제 링크
https://www.acmicpc.net/problem/2804
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
Pair p = new Pair(br.readLine());
int[] loc = getLocation(p);
for (int i = 0, k = 0; i < p.y; i++, sb.append('\n')) {
if (i == loc[0]) {
sb.append(p.a);
k++;
} else for (int j = 0; j < p.x; j++) sb.append(j == loc[1] ? p.b.charAt(k++) : '.');
}
bw.write(sb.toString());
bw.flush();
}
private static int[] getLocation(Pair p) {
for (int i = 0; i < p.x; i++)
for (int j = 0; j < p.y; j++) if (p.a.charAt(i) == p.b.charAt(j)) return new int[]{j, i};
return new int[]{0, 0};
}
private static class Pair {
String a, b;
int x, y;
Pair(String s) {
int i = s.indexOf(' ');
this.a = s.substring(0, i);
this.b = s.substring(i + 1);
this.x = a.length();
this.y = b.length();
}
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 10769 행복한지 슬픈지 - Implementation / Java (0) | 2025.07.30 |
---|---|
[백준] 11816 8진수, 10진수, 16진수 - Implementation / Java (0) | 2025.07.29 |
[백준] 9455 박스 - Implementation / Java (0) | 2025.07.27 |
[백준] 1551 수열의 변화 - Implementation / Java (0) | 2025.07.26 |
[백준] 2985 세 수 - Implementation / Java (0) | 2025.07.25 |
댓글