Your question states that you want to solve this problem in C++
/C++14
. In your solution you are mainly using old C
style code.
In order to make your code more readable / maintable / bug-free (you choose!), try to make use of STL
as much as possible.
std::vector< bool >##
Using std::vector<bool>
as the binary representation we can make use of the algorithm
library of STL.
STL iterators
When dealing with containers in STL, iterator
s are used to specify a range for a container. These begin
and end
iterators (specifying a range) are needed for the algorithms.
STL algorithm
The STL algorithm
module has most of algorithms you need for manipulating containers.
Try to use STL algorithms as much as possible whenever you need to operate on a range of elements.
Here is another approach using std::vector<bool>
, iterator
s and algorithm
from STL.
Here is another approach using std::vector<bool>
, iterator
s and algorithm
from STL.
Your question states that you want to solve this problem in C++
/C++14
. In your solution you are mainly using old C
style code.
In order to make your code more readable / maintable / bug-free (you choose!), try to make use of STL
as much as possible.
std::vector< bool >##
Using std::vector<bool>
as the binary representation we can make use of the algorithm
library of STL.
STL iterators
When dealing with containers in STL, iterator
s are used to specify a range for a container. These begin
and end
iterators (specifying a range) are needed for the algorithms.
STL algorithm
The STL algorithm
module has most of algorithms you need for manipulating containers.
Try to use STL algorithms as much as possible whenever you need to operate on a range of elements.
Here is another approach using std::vector<bool>
, iterator
s and algorithm
from STL.
#LIVE DEMO #