반응형
문제
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.util.Scanner;
public class Main {
// USACO Mad Scientist
// 백준 18787
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
String s1 = sc.nextLine();
String s2 = sc.nextLine();
int cnt = 0; //변환 횟수
boolean isChange = false; //방금 변환 했는지 ?
for (int i = 0; i < s1.length(); i++) {
if (s1.charAt(i) != s2.charAt(i)) { //변환 해야함
if (!isChange) ++cnt; //이전에 변환 안했으면 카운트 증가
isChange = true; //변환 O
} else {
isChange = false; //변환 X
}
}
System.out.println(cnt);
}//main
}//class
반응형
'개발 > 알고리즘' 카테고리의 다른 글
[USACO] Word Processor JAVA (0) | 2021.02.24 |
---|---|
[USACO] Just Stalling JAVA (0) | 2021.02.23 |
[USACO] Even More Odd Photos JAVA (0) | 2021.02.23 |
[USACO] Uddered but not Herd JAVA (0) | 2021.02.23 |
[USACO] Swapity Swap JAVA (0) | 2021.02.23 |
최근댓글