Let say I've an std:array<int> such as:
0 1 1 1 0 1 1 0
I'd like to use std (if possible) to do this in c++11:
- sum adjacent 1's
- erase the summed value
- transform 0 to 1
So getting this result for the example above:
1 3 1 2 1
Thanks
Let say I've an std:array<int> such as:
0 1 1 1 0 1 1 0
I'd like to use std (if possible) to do this in c++11:
So getting this result for the example above:
1 3 1 2 1
Thanks
You could apply this logic with a single pass through the input values, while creating the result vector:
As to
std::array: as this is a fixed size data type, and the size of the result is unknown beforehand, I would use vectors instead. But I added the code to convert the array to a vector. If your requirements don't insist onarray, you could of course have your input represented by astd::vectorfrom the very start: