-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
158 lines (131 loc) · 2.74 KB
/
Source.cpp
File metadata and controls
158 lines (131 loc) · 2.74 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <iostream>
#include <string>
#include <list>
#include <queue>
#include <fstream>
using namespace std;
typedef list<int> Vertex;
typedef list<Vertex> Graph;
typedef Vertex::iterator vIterator;
typedef Graph::iterator gIterator;
void removeWhite(string& s) {
for (int i = 0; i < s.length(); i++) {
if (s[i] == ' ')
s.erase(s.begin() + i);
}
}
/*
void read() {
fstream fstr;
fstr.open("C:/Users/grade/Desktop/test.txt");
string str = "";
char c;
while (!fstr.eof()) {
c = fstr.get();
while (c != '\n' && !fstr.eof()) {
str += c;
c = fstr.get();
}
cout << str << endl;
removeWhite(str);
int* temp = new int[str.length()];
fstr.seekg(fstr.tellg - str.length());
str = "";
}
}
*/
gIterator point(Graph& g, int a) {
gIterator git = g.begin();
for (; git != g.end(); git++) {
if (git->front() == a)
return git;
}
return git;
}
bool isInVisited(gIterator& l, int a) {
vIterator vit = l->begin();
for (; vit != l->end(); vit++) {
if (*vit == a)
return true;
}
return false;
}
Vertex shortestPath(Graph& g, gIterator start, gIterator& target) {
queue<int> help;
Vertex visited;
visited.push_back(start->front());
Vertex path;
path.push_back(start->front());
while (start != target) {
for (vIterator vit = start->begin(); vit != start->end(); vit++) {
if (!isInVisited(start, *vit)) {
visited.push_back(*vit);
help.push(*vit);
}
start = point(g, help.front());
path.push_back(start->front());
help.pop();
}
}
return path;
}
struct node {
char c;
node* left;
node* right;
};
int* split(string const & input) {
int* out = new int[input.length() + 1];
for (int i = 0; i < input.length(); i++) {
if (input[i] == '.')
out[i] = 1;
else if (input[i] == '-')
out[i] = 2;
else
out[i] = 0;
}
out[input.length()] = 0;
return out;
}
string decipher(node* root, string const & input) {
node* q = root;
string out = "";
int* in = split(input);
for (int i = 0; i < input.length() + 1; i++) {
if (in[i] == 1)
q = q->left;
if (in[i] == 2)
q = q->right;
if(in[i] == 0) {
out += q->c;
q = root;
}
}
return out;
}
int main(){
node M = { 'M', NULL, NULL };
node N = { 'N', NULL, NULL };
node T = { 'T', &N, &M };
node A = { 'A', NULL, NULL };
node I = { 'I', NULL, NULL };
node E = { 'E', &I, &A };
node root = { 'R', &E, &T };
fstream temp;
char c;
temp.open("C:/Users/grade/Desktop/test.txt");
c = temp.get();
cout << c;
c = temp.get();
cout << c;
c = temp.get();
cout << c;
long p = temp.tellg();
p -= 2;
temp.seekg(p);
c = temp.get();
cout << c;
int tempa;
cin >> tempa;
return 0;
}