In Marjar University, students in College of Computer Science will learn EON (Edward Object Notation), which is a hierarchical data format that uses human-readable text to transmit data objects consisting of attribute-value pairs. The EON was invented by Edward, the headmaster of Marjar University.
The EON format is a list of key-value pairs separated by comma ",", enclosed by a couple of braces "{" and "}". Each key-value pair has the form of "
To retrieve the data from an EON text, we can search it by using a key. Of course, the key can be in a nested form because the value may be still an EON. In this case, we will use dot "." to separate different hierarchies of the key.
For example, here is an EON text:
{"headmaster":"Edward","students":{"student01":"Alice","student02":"Bob"}}
As a student in Marjar University, you are doing your homework now. Please write a program to parse a line of EON and respond to several queries on the EON.
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains an EON text. The number of colons ":" in the string will not exceed 10000 and the length of each key and non-EON value will not exceed 20.
The next line contains an integer Q (0 <= Q <= 1000) indicating the number of queries. Then followed by Q lines, each line is a key for query. The querying keys are in correct format, but some of them may not exist in the EON text.
The length of each hierarchy of the querying keys will not exceed 20, while the total length of each querying key is not specified. It is guaranteed that the total size of input data will not exceed 10 MB.
For each test case, output Q lines of values corresponding to the queries. If a key does not exist in the EON text, output "Error!" instead (without quotes).
1 {"hm":"Edward","stu":{"stu01":"Alice","stu02":"Bob"}} 4 "hm" "stu" "stu"."stu01" "students"
"Edward" {"stu01":"Alice","stu02":"Bob"} "Alice" Error!
Author: LU, Yi
题意:
模拟python的字典。给出一个字典,然后有1000个查询,输出对应的键值。
分析:
简单粗暴的字符串神烦模拟。因为打的网络同步赛,内存限制得很死,采用了离线操作。
抓住这几个关键的符号:‘{’ '}' ',' ':' 进行操作。具体见代码及注释,数据不是非常恶心。
#include
#include
#include
#include
#include
#include
#include
#include
#include