페이지

2806번: DNA 발견

https://www.acmicpc.net/problem/2806

#include<stdio.h>
const int MAX_N = 1e6;
int n, cnt;
char str[MAX_N + 1];
int main() {
    scanf("%d %s", &n, &str);
    str[n] = 'A';
    for (int i = 0; i <n; i++) {
        if (str[i] != str[i + 1]) {
            cnt++;
            if (i && str[i - 1] == str[i + 1]) cnt--, str[i] = str[i + 1];
        }
    }
    printf("%d", cnt);
    return 0;
}

댓글 없음 :

댓글 쓰기