小红的01串 坏串“010” “101” 每次可以翻转1位,求坏串变成好串需要的最少翻转次数#include <iostream>#include <string>using namespace std;bool isTrue(string&amp; s, int&amp; err) {for (unsigned long i = 0; i < s.size() ; i++) {if (s[i] == '0') {if (s.substr(i, 3) == &quot;010&quot;) {err = i;return false;}}if (s[i] == '1') {if (s.substr(i, 3) == &quot;101&quot;) {err = i;return false;}}}return true;}int reverse(string&amp; s, int&amp; err, int&amp; count) {if (isTrue(s, err)) {return 0;}int idx = err+1;if (s[err] == '1') {s[idx] = '1';} else {s[idx+1] = '1';}count++;// cout <<&quot;reverse:&quot; <<s<<endl;reverse(s, err, count);return 0;}int main() {int a;cin >> a;string s = to_string(a);int err = 0, count = 0;reverse(s, err, count);cout<<count;}// 64 位输出请用 printf(&quot;%lld&quot;)