-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
70 lines (65 loc) · 2.09 KB
/
main.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
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include "graph.h"
using namespace std;
int main(){
string myText;
Graph grafo;
string ponctuationCaracters[] = {".",",",";","!","?"};
vector<Vertice> *graphVertices = grafo.getVerticesArray();
vector<string> wordsArray;
string fileName;
cout << "Insira o nome do arquivo que será utilizado: " <<endl;
cin >> fileName;
ifstream MyReadFile(fileName);
while(getline(MyReadFile, myText)){
string word = "";
for (int index = 0;index <= myText.length() ; index++) {
int comparisonResult = strncmp(&myText[index], " ", 1);
int endOfLine = strncmp(&myText[index], "\0", 1);
if (comparisonResult != 0 && endOfLine != 0 ){
word += tolower(myText[index]);
}else {
wordsArray.push_back(word);
if (ispunct(word.back())){
string s = word;
s.pop_back();
grafo.addVertice(s);
}else {
grafo.addVertice(word);
}
if(wordsArray.size() > 1){
if (ispunct(wordsArray.end()[-2].back())){
}else if(ispunct(wordsArray.end()[-1].back())){
string wordCopy = wordsArray.end()[-1];
wordCopy.pop_back();
grafo.addAresta(wordsArray.end()[-2], wordCopy);
}else{
grafo.addAresta(wordsArray.end()[-2], wordsArray.end()[-1]);
}
}
word = "";
}
}
}
MyReadFile.close();
cout << "-------------VERTICES COM PESOS-------------------"<<endl;
for (int i = 0; i < graphVertices->size(); i++) {
cout << (*graphVertices)[i].getName() << " :"
<< (*graphVertices)[i].getWeight() << endl;
}
cout << "vertice que mais aparece: " << grafo.getMostUsedVerticeName()<<endl;
cout <<endl;
cout << "-------------ARESTA QUE MAIS APARECE---------------"<<endl;
cout << grafo.getMostUsedAresta().getStartVertice()->getName() <<endl;
cout << grafo.getMostUsedAresta().getEndVertice()->getName() <<endl;
return 1;
};