-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path20170903.cpp
More file actions
128 lines (124 loc) · 1.54 KB
/
20170903.cpp
File metadata and controls
128 lines (124 loc) · 1.54 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
#include <iostream>
#include <string>
#include <map>
using namespace std;
int n, m;
string s, str;
bool key;
map<string, string> json;
string handle(string str, string s)
{
if (s.empty())
{
return str;
}
for (int i = 0; i < s.size(); i++)
{
if (s[i] == ' ')
{
continue;
}
else if (s[i] == '{')
{
json[str] = "OBJECT";
key = true;
}
else if (s[i] == '}')
{
int i;
for (i = str.size() - 1; i >= 0; i--)
{
if (str[i] == '.')
{
break;
}
}
if (i < 0)
{
str = "";
}
else
{
str = str.substr(0, i);
}
}
else if (s[i] == ':')
{
key = false;
}
else if (s[i] == ',')
{
key = true;
}
else if (s[i] == '"')
{
string temp;
for (i = i + 1; i < s.size(); i++)
{
if (s[i] == '\\')
{
i++;
temp += s[i];
}
else if (s[i] == '"')
{
break;
}
else
{
temp += s[i];
}
}
if (key)
{
if (str == "")
{
str = temp;
}
else
{
str += '.' + temp;
}
}
else
{
json[str] = "STRING " + temp;
int i;
for (i = str.size() - 1; i >= 0; i--)
{
if (str[i] == '.')
{
break;
}
}
if (i < 0)
{
str = "";
}
else
{
str = str.substr(0, i);
}
}
}
}
return str;
}
int main()
{
std::ios::sync_with_stdio(false);
cin >> n >> m;
cin.get();
getchar();
while (n--)
{
getline(cin, s);
str = handle(str, s);
}
while (m--)
{
cin >> s;
cout << (json[s] == "" ? "NOTEXIST" : json[s]) << endl;
}
return 0;
}