Problem Solving/Baekjoon
[백준] 18787 Mad Scientist - Greedy / Java
graycode
2023. 7. 13. 20:20
• 문제 링크
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();
}
}