-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayf.cpp
More file actions
95 lines (81 loc) · 1.9 KB
/
arrayf.cpp
File metadata and controls
95 lines (81 loc) · 1.9 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "arrayf.hpp"
#include "stringf.hpp"
#include <algorithm>
#include <sstream>
vvint vrotate(vvint &origin){
vvint resh;
resh=vvint(origin[0].size(),vint(origin.size()));
lop(i,0,resh.size())
lop(r,0,origin.size())resh[i][r]=origin[r][i];
return resh;
}
int qtdiguais(vint &a,vint &b){
int qtdig=0;
lop(i,0,a.size())
lop(o,0,b.size())
if(a[i]==b[o])
qtdig++;
return qtdig;
}
vector<string> split(const string& s, const string delim, const bool keep_empty) {
vector<string> result;
if (delim.empty()) {result.push_back(s);
return result;}
string::const_iterator substart = s.begin(), subend;while (true) {
subend = search(substart, s.end(), delim.begin(), delim.end());
string temp(substart, subend); if (keep_empty || !temp.empty()) {
result.push_back(temp); }if (subend == s.end()) {break; }
substart = subend + delim.size(); }
return result;}
vfloat numsFromStr(string& s){
trim(s);
vstring v=split((s),",");
vfloat r;
lop(i,0,v.size()){
trim( v[i]);
if(v[i].size()==0)continue;
r.push_back(atof(v[i].c_str()));
}
return r;
}
string join(vint v,string sep){
stringstream ss;
for(size_t i = 0; i < v.size(); ++i)
{
if(i != 0)
ss << sep;
ss << v[i];
}
return ss.str();
}
void vecpushuni(vstring &vec,string val){
bool flag=0;
lop(i,0,vec.size()){
if(vec[i]==val)flag=1;
}
if(!flag)vec.push_back(val);
}
void vecpushuni(vint &vec,int val){
bool flag=0;
lop(i,0,vec.size()){
if(vec[i]==val)flag=1;
}
if(!flag)vec.push_back(val);
}
//int vboolToInt(vbool b){
// return accumulate(b.rbegin(), b.rend(), 0, [](int x, int y) { return (x << 1) + y; });
//}
//not tested
//vbool intTovbool(uint vb,int sz=32){
// vbool ret(sz);
// int i=0;
// for (unsigned int mask=0x80000000; mask; mask>>=1) {
// if (x & mask) ret[i]=1;
// if(i++>sz)break;
// }
// return ret;
//}
//= a==b
//bool vboolCompare(vbool &a,vbool &b){
// return a.begin()._M_p==b.begin()._M_p;
//}