USACO/Bronze

백준 18787 Mad Scientist (USACO February 2020 Bronze 2번)

ssam.. 2020. 3. 23. 13:16

문제 링크: https://www.acmicpc.net/problem/18787

 

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

예시

7

GHHHGHH

HHGGGHH

앞에서부터 훑으면서 첫번째 자리가 다르므로 한번 toggle해주고, 세번째~네번째 자리가 다르므로 한번 더 toggle해줘서 총 2번이 답임.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <bits/stdc++.h>
using namespace std;
 
int n;
string a, b;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    cin >> n >> a >> b;
 
    int ans = 0;
    bool flag = true;
    for(int i = 0; i < n; i++) {
        if(flag && a[i] != b[i]) {
            flag = false;
            ans++;
        }
        if(a[i] == b[i]) {
            flag = true;
        }
    }
 
    cout << ans << '\n';
    return 0;
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter