-
Notifications
You must be signed in to change notification settings - Fork 0
/
generar.cc
65 lines (48 loc) · 1.32 KB
/
generar.cc
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
//programa per generar sopes i desar-les en un fitxer
#include <iostream>
#include <fstream>
#include "./SuperSopa/superSopa.hh"
using namespace std;
void llegir_fitxer (vector<string>& v, const string& path) {
ifstream fp_in;
string a;
fp_in.open(path);
while (fp_in >> a) {
v.push_back(a);
}
fp_in.close();
}
//escriu la sopa al final del fitxer path
void escriure_fitxer(Sopa& sopa, ofstream& fw) {
int n = sopa.size();
fw << n << ' ';
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
fw << sopa[i][j];
}
}
fw << endl;
}
int main () {
string path = "sopes.txt";
string pathDiccionari = "./diccionaris/quijote-vocabulary-6.txt";
vector<string> diccionari;
superSopa super_sopa;
ofstream fw(path, ofstream::out);
llegir_fitxer(diccionari, pathDiccionari);
vector<string> p;
int a;
srand(time(NULL));
for(int i = 0; i < 20; ++i) {
a = rand() % diccionari.size();
p.push_back(diccionari[a]);
}
for (int n = 10; n <= 55; n += 5) {
for (int j = 0; j < 10; ++j) {
Sopa matriu = Sopa(n, vector<char>(n, '#'));
super_sopa.generarSopa(p, matriu);
escriure_fitxer(matriu, fw);
}
}
fw.close();
}