Codeforces Round 855 (Div. 3)--D

发布时间 2023-04-30 13:42:35作者: zhujio

题意:

  给定一个字符串,删除其中连续两个字符,问有多少种不同字符串的情况

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
//开始时假设每个点都对答案有贡献,考虑什么时候没有贡献
//假如字符串某处出现aba这种
//删除ab或者ba最后都是a这种时候就对答案没有贡献,ans--
int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int T =1;    cin >> T;
    while (T--) {
        int n;string s;
        cin >> n >> s;
        ll ans = n-1;
        for (int i = 0; i < n; i++) {
            if (i + 2 < n && s[i] == s[i + 2])ans--;
        }
        cout << ans << endl;
    }
    return 0;
}