• 문제 링크
https://www.acmicpc.net/problem/5218
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
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();
int t = Integer.parseInt(br.readLine());
while (t-- > 0) {
StringTokenizer st = new StringTokenizer(br.readLine());
String a = st.nextToken(), b = st.nextToken();
sb.append("Distances: ");
for (int i = 0; i < a.length(); i++) sb.append(dist(a.charAt(i), b.charAt(i))).append(" ");
sb.append("\n");
}
bw.write(sb.toString());
bw.flush();
}
private static int dist(char a, char b) {
return a <= b ? b - a : b + 26 - a;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 14455 Don't Be Last! - Data Structure / Java (0) | 2025.02.04 |
---|---|
[백준] 2511 카드놀이 - Implementation / Java (0) | 2025.02.03 |
[백준] 5586 JOI와 IOI - Implementation / Java (0) | 2025.02.01 |
[백준] 1371 가장 많은 글자 - Implementation / Java (0) | 2025.01.31 |
[백준] 23037 5의 수난 - Implementation / Java (0) | 2025.01.30 |
댓글