题意:给你一个01串,必须替换一次,且替换的为子串。问换完后,最大01串长度。
1 #include <bits/stdc++.h> 2 typedef long long ll; 3 using namespace std; 4 int main() 5 { 6 int n,sum = 1; 7 string s; 8 cin >> n >> s; 9 char last = s[0]; 10 for(int i = 1 ; i < n ; i ++) 11 { 12 if(last != s[i]) 13 { 14 sum ++; 15 last = s[i]; 16 } 17 } 18 if(sum >= n - 1) 19 cout << n << endl; 20 else 21 cout << sum + 2 << endl; 22 return 0; 23 }