-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount_bits.cpp
More file actions
43 lines (40 loc) · 780 Bytes
/
count_bits.cpp
File metadata and controls
43 lines (40 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
// int bits(int num){
// int count = 0;
// while(num){
// count += num & 1;
// num >>= 1 ;
// }
// return count;
// }
// std::string num_to_bin(int num){
// std::string s;
// int start = 0;
// while(num){
// s += (num % 2) + '0';
// num /= 2;
// }
// std::reverse(begin(s), end(s));
// return s;
// }
template <typename iterator, typename T>
void my_iota(iterator b, iterator e, T value, T step){
while(b!=e){
value += step;
*b += value;
b++;
}
}
int main(){
std::vector<int> v;
v.resize(15);
my_iota(v.begin(), v.end(), 100, 1);
for(auto & i: v){
std::cout << i << '\n';
}
//std::cout << num_to_bin(num) << '\n';
return 0;
}