#include <bits/stdc++.h>
using
namespace
std;
void
findOperations(string A,
string B,
int
N)
{
int
operations = 0;
vector<
int
> ops;
bool
invert =
false
;
for
(
int
i = N - 1; i >= 0; i--) {
if
(A[i] != B[i]) {
if
(!invert) {
operations++;
ops.push_back(i + 1);
invert =
true
;
}
}
else
{
if
(invert) {
operations++;
ops.push_back(i + 1);
invert =
false
;
}
}
}
cout << operations << endl;
if
(operations != 0) {
for
(
auto
x : ops)
cout << x <<
" "
;
}
}
int
main()
{
string A =
"001"
, B =
"000"
;
int
N = A.size();
findOperations(A, B, N);
return
0;
}
Original page link
Best Cool Tech Gadgets
Top favorite technology gadgets
0 comments:
Post a Comment