-
Notifications
You must be signed in to change notification settings - Fork 2
/
minmax.h
78 lines (62 loc) · 1.84 KB
/
minmax.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
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
#ifndef MINMAX_H_INCLUDED
#define MINMAX_H_INCLUDED
float round(float f,int t=3)
{
int v = pow(10,t);
float value = (int)(f * v + .5);
return (float)value / v;
}
template <class T>
std::vector<float> minmaxstandard(std::vector<T> v)
{
if(v.size()==1) throw std::runtime_error("Not a range");
std::vector<float> v1(v.begin(),v.end());
std::sort(v.begin(),v.end());
float min = v.front();
float max = v.back();
for(size_t i=0; i<v1.size(); i++)
{
v1[i] = (v1[i]-min)/(max-min)*(1-0)+0;
v1[i] = round(v1[i]);
}
return v1;
}
template <class T, class S>
void minmaxprint(std::vector<T> v, std::vector<S> standard)
{
std::cout << std::fixed << std::setprecision(2);
if(v.size()!=standard.size()) throw std::runtime_error("Not equal sizes");
for(size_t i=0;i<v.size();i++)
{
std::cout << v[i] << "\t|\t" << standard[i] << "\n";
}
std::endl(std::cout);
}
template <class T, class S>
void maxprint(std::vector<T> v, std::vector<S> standard)
{
if(v.size()!=standard.size()) throw std::runtime_error("Not equal sizes");
for(size_t i=0;i<v.size();i++)
{
std::cout << v[i] << "\t|\t" << standard[i] << "\n";
}
std::endl(std::cout);
}
template <class T, class S>
void print(std::vector<T> one, std::vector<S> two, std::vector<T> three, std::vector<T> four)
{
if(one.size()!=two.size()
||
two.size()!=three.size()
||
three.size()!=four.size()) throw std::runtime_error("Not equal sizes");
for(size_t i=0;i<one.size();i++)
{
std::cout << one[i] << "\t|\t"
<< two[i] << "\t|\t"
<< three[i] << "\t|\t"
<< four[i] << "\n";
}
std::endl(std::cout);
}
#endif // MINMAX_H_INCLUDED