-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.cpp
71 lines (55 loc) · 1021 Bytes
/
util.cpp
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
#include <fstream>
#include <cstring>
#include "util.h"
int minim(int a, int b, int c)
{
return MINIM(MINIM(a, b), c);
}
string remove_white_space(string str)
{
string str2(" ");
size_t found;
while((found = str.find(str2)) != string::npos)
str.erase(found, str2.length());
return str;
}
dictionar get_from_file()
{
string cuv;
int frecv;
dictionar d;
FILE *f;
ifstream fin;
fin.open(DICTFILE, ifstream::in);
while(fin >> cuv >> frecv) {
d.insert(pair<string, int>(cuv, frecv));
}
fin.close();
return d;
}
prop set_prop(string cuvant, int freq, int deviatie)
{
prop newstruct;
newstruct.deviatie = deviatie;
newstruct.freq = freq;
newstruct.cuvant = cuvant;
return newstruct;
}
vector<prop> new_vector_prop(int dim)
{
vector<prop> p;
prop tmp;
int i;
for(i = 0; i < dim; ++i) {
tmp = set_prop("", -1, INF);
p.push_back(tmp);
}
return p;
}
string citeste_termeni()
{
char in[INSTR_SIZE];
fgets(in, INSTR_SIZE, stdin);
in[strlen(in) - 1] = '\0';
return string(in);
}