【題解】Codeforces 665C. Simple Strings

【題目敘述】https://codeforces.com/contest/665/problem/C
【解題想法】Greedy

#include <bits/stdc++.h>
using namespace std;
 
string s;
 
int main(){
    cin >> s;
    for (int i = 1; i < s.length(); i++){
        if (s[i] == s[i-1]){
            s[i] = (char)'a'+(s[i-1]-'a'+1)%26;
            if (i+1 < s.length() && s[i] == s[i+1]) s[i] = (char)'a'+(s[i]-'a'+1)%26;
        }
    }
    cout << s << "\n";
}
分享本文 Share with friends