The basic idea:
Greedy grasp the idea is not very good, in the case of missing an enumeration:
010
111
At this time, twice requiring inversion;
If you use a greedy strategy, it is the moment to find the optimal solution, namely: direct encounter different direct translation, followed by a subsequent judgment;
key point:
no;
#include<iostream> #include<stdlib.h> #include<stdio.h> #include<vector> #include<string> #include<math.h> #include<algorithm> #include<cstring> #include<map> #include<queue> #include<set> #include<stack> using namespace std; int main() { string s1, s2; CIN >> >> S1 S2; int CNT = 0 ; for ( int I = 0 ; I <s1.size (); I ++ ) { IF (! S1 [I] = S2 [I]) { // when encountering when not equal; IF (S1 [I + . 1 ] == ' * ' ) S1 [i + 1 ] = ' O ' ; presence S1 [i + 1 ] = ' * ' ; cnt++; } } cout << cnt; return 0; }