• 문제 링크
18787번: Mad Scientist
First, FJ can transform the substring that corresponds to the first character alone, transforming $B$ into GHGGGHH. Next, he can transform the substring consisting of the third and fourth characters, giving $A$. Of course, there are other combinations of t
www.acmicpc.net
• 풀이 과정
• 풀이 코드
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());
String a = br.readLine();
String b = br.readLine();
boolean flag = false;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (a.charAt(i) != b.charAt(i)) {
if (!flag) cnt++;
flag = true;
} else flag = false;
}
bw.write(String.valueOf(cnt));
bw.flush();
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 14620 꽃길 - Brute Force / Java (0) | 2023.07.15 |
---|---|
[백준] 16471 작은 수 내기 - Greedy / Java (0) | 2023.07.15 |
[백준] 3213 피자 - Greedy / Java (0) | 2023.07.12 |
[백준] 20937 떡국 - Greedy / Java (0) | 2023.07.11 |
[백준] 17451 평행 우주 - Greedy / Java (0) | 2023.07.10 |
댓글