2014牡丹江區域賽H(字典樹)ZOJ3826

Hierarchical Notation

Time Limit: 2 Seconds      Memory Limit: 131072 KB

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 "<key>":"<value>". <key> is a string consists of alphabets and digits. <value> can be either a string with the same format of <key>, or a nested EON.

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"}}

  • For the key "headmaster", the value is "Edward".
  • For the key "students", the value is {"student01":"Alice","student02":"Bob"}.
  • For the key "students"."student01", the value is "Alice".

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.

Input

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.

Output

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).

Sample Input

1
{"hm":"Edward","stu":{"stu01":"Alice","stu02":"Bob"}}
4
"hm"
"stu"
"stu"."stu01"
"students"

Sample Output

"Edward"
{"stu01":"Alice","stu02":"Bob"}
"Alice"
Error!

題意:RT

思路:這題隊友A的,字典樹的應用

            然後一層一層(左右括號)存的時候用棧即

            直接存所有可能的索引的字典樹,然後值爲索引對應在原串上的起始和結束位置

            查詢的時候直接將索引在字典樹上查,然後讀出左右位置輸出即可

#include 
#include 
#include 
#include 
using namespace std;

const int MAXN = 401000;
const int MAXNODE = 200000;

char s[MAXN];
char qz[MAXN];
int bk[MAXN];
int st[MAXN];

int ch[MAXNODE][27];
int val[MAXNODE][2];
int sz;

inline void init(){
    sz=1; memset(ch[0],0,sizeof(ch[0]));
}

struct Trie{
    int idx(char c) { if(c=='.') return 26; return c-'a'; }

    int insert(char* s,int u,int x,int y){
        int n=strlen(s);
        for(int i=0;i
發佈了147 篇原創文章 · 獲贊 7 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章