-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathattribute_parser.cpp
61 lines (51 loc) Β· 1.38 KB
/
attribute_parser.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
#include "iostream"
#include <map>
using namespace std;
map <string, string> tagMap;
void createMap(int &n, string pretag) {
if(!n) return;
string line, tag, attr, value;
getline(cin, line);
int i=1;
if(line[i]=='/') { // found closing tag
while(line[i]!='>') i++;
if(pretag.size()>(i-2)) // update tag
tag = pretag.substr(0,pretag.size()-i+1);
else
tag = "";
}
else { // found opening tag
while(line[i]!=' ' && line[i]!='>') i++;
tag = line.substr(1,i-1); // update tag
if(pretag!="") tag = pretag + "." + tag;
int j;
while(line[i]!='>') { // go through attributes
j = ++i;
while(line[i]!=' ') i++;
attr = line.substr(j,i-j); // attribute name
while(line[i]!='\"') i++;
j = ++i;
while(line[i]!='\"') i++;
value = line.substr(j,i-j); // attribute value
i+= 1;
tagMap[tag + "~" + attr] = value;
}
}
createMap(--n, tag);
}
int main() {
int n, q;
cin >> n >> q;
cin.ignore();
createMap(n,"");
string attr, value;
while(q--) {
getline(cin, attr);
value = tagMap[attr];
if(value == "") {
value = "Not Found!";
}
cout << value << endl;
}
return 0;
}