-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAtributeParser.cpp
52 lines (50 loc) · 1.16 KB
/
AtributeParser.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
#include <vector>
#include <iostream>
#include <algorithm>
#include <regex>
using namespace std;
int main(int argc, char const *argv[])
{
int n,q;
cin >> n >>q;
string line;
getline(cin,line);
regex opentag ("<([\\w]+)");
regex expression ("(\\S+)\\s\\=\\s\"(\\S+)\"");
smatch matched;
string currCaller = "";
map<string,string> variables;
for (int i = 0; i < n; ++i)
{
getline(cin,line);
regex_search(line, matched, opentag);
if (matched[0] != ""){ //open tag
currCaller += matched[1];
currCaller += ".";
while(regex_search(line, matched, expression)){
currCaller.pop_back();
string key = currCaller + "~" + matched[1].str();
variables[key] = matched[2];
currCaller += ".";
line = matched.suffix();
}
} else{//closing tag
currCaller.pop_back();
size_t extension = currCaller.find_last_of(".");
if (extension == string::npos) currCaller = "";
else{
currCaller = currCaller.substr(0,extension);
currCaller += ".";
}
}
}
for (int i = 0; i < q; ++i)
{
string querry;
cin >> querry;
string res;
res = variables[querry];
if (res == "") cout << "Not Found!" << endl;
else cout << res << endl;
}
}