-
Notifications
You must be signed in to change notification settings - Fork 0
/
langUtils.h
55 lines (38 loc) · 908 Bytes
/
langUtils.h
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
44
45
46
47
48
49
50
51
52
#include<string>
#include<vector>
#include<iostream>
#include<math.h>
template <class T>
std::vector<T> digitize(T n){
std::string aux = std::to_string(n);
std::vector<T> res(aux.size());
//std::vector res(aux.size());
for (int i = 0; i< aux.size(); i++)
res[i] = int(aux[i]) - int('0');
return res;
}
int decToBinF(int n, int counter){
if (n < 2)
return n * std::pow(10,counter);
else
return n%2 * std::pow(10,counter) + decToBinF(n/2, counter+1);
}
int decToBin(int n){
return decToBinF(n,0);
}
std::vector<bool> vIntTovBool (std::vector<int> v){
std::vector<bool> res(v.size());
for (int i = 0; i<v.size(); i++)
res[i] = bool(v[i]);
return res;
}
template <class T>
void printVector(std::vector<T> v){
std::cout << '[';
for (int i = 0; i < v.size() ; i++){
std::cout << v[i];
if ( i+1 != v.size() )
std::cout << ',';
}
std::cout << ']' << std::endl;
}