• 문제 링크
https://www.acmicpc.net/problem/30314
• 풀이 코드
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));
int n = Integer.parseInt(br.readLine()), sum = 0;
String a = br.readLine(), b = br.readLine();
while (n-- > 0) sum += calc(a.charAt(n) - 'A', b.charAt(n) - 'A');
bw.write(String.valueOf(sum));
bw.flush();
}
private static int calc(int a, int b) {
return Math.min(Math.abs(a - b), 26 - Math.abs(a - b));
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 24855 Natives - Greedy / Java (0) | 2025.04.12 |
---|---|
[백준] 26511 Complexity - Greedy / Java (0) | 2025.04.11 |
[백준] 7130 Milk and Honey - Greedy / Java (0) | 2025.04.09 |
[백준] 30018 타슈 - Greedy / Java (0) | 2025.04.08 |
[백준] 4466 A Smart Brain is a Tasty Brain - Data Structure / Java (0) | 2025.04.07 |
댓글