模拟: 语法的分析

hash一切Key建设规划,对于记录在几个地点的每个节点原始的字符串开始输出。

。。

对每一个询问沿图走就能够了。

。。

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!

Author: LU, Yi
Source: The 2014 ACM-ICPC Asia Mudanjiang Regional Contest

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <stack>using namespace std;typedef long long int LL;LL hash(char* str)
{LL ret=0;int len=strlen(str);for(int i=0;i<len;i++){ret=ret*123+(LL)(str[i]-'0');}return ret;
}map<LL,int> mp;
stack<int> stk;char str[400007],que[400007];
bool graph[10000][10000];
int stpt[400007];void init()
{mp.clear(); while(!stk.empty()) stk.pop();memset(graph,false,sizeof(graph));
}int main()
{int T_T;scanf("%d",&T_T);while(T_T--){init();scanf("%s",str);int len=strlen(str);int word=0;bool readname=false;char name[50]; int na;for(int i=0;i<len;i++){if(str[i]=='{') stk.push(word);else if(str[i]=='}') stk.pop();else if(str[i]=='"'){if(readname==false){readname=true;memset(name,0,sizeof(name)); na=0;}else if(readname==true){readname=false;LL id=hash(name);word++;mp[id]=word;stpt[mp[id]]=i+1;graph[stk.top()][word]=true;}}else if(str[i]==':'){if(str[i+1]=='{') continue;else if(str[i+1]=='"'){i++;while(str[i+1]!='"')i++;i++;}}else if(readname==true){name[na++]=str[i];}}int m;scanf("%d",&m);while(m--){scanf("%s",que);int len2=strlen(que);bool flag=true;na=0; int p=0;readname=false;for(int i=0;i<len2&&flag;i++){if(que[i]=='"'){if(readname==false){na=0; memset(name,0,sizeof(name));readname=true;}else if(readname==true){readname=false;LL id=hash(name);if(graph[p][mp[id]]==true){p=mp[id];}else flag=false;}}else if(que[i]=='.') continue;else name[na++]=que[i];}if(flag==false) puts("Error!");else{char cc=str[stpt[p]+1];int dep=0;if(cc=='{') cc='}';int ii=stpt[p]+1;if(cc=='"') { ii++; putchar('"'); }while(true){if(cc=='}'){if(str[ii]=='{') dep++;if(str[ii]=='}') dep--;if(dep==0) break;}else if(cc=='"'){if(str[ii]=='"') break;}putchar(str[ii]); ii++;}putchar(cc);putchar(10);}}}return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

转载于:https://www.cnblogs.com/yxwkf/p/4629168.html

ZOJ 3826 Hierarchical Notation 模拟相关推荐

  1. ZOJ 3822 Known Notation(2014牡丹江Regional K题)

    题目大意:给你一个不完整的后缀表达式和两种操作,一是插入一个数或者"*"运算号,另一个是把数字和"*"交换. 一个*至少对应两个数字,而一个表达式又等于一个数字 ...

  2. ZOJ 3879(大模拟)

    传送门 题面:Capture the Flag Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge In comp ...

  3. 2014牡丹江——Hierarchical Notation

    题目链接 字符串模拟 const int MAXN = 2000000;char ipt[MAXN], t[MAXN]; int f[MAXN], len, to[MAXN]; map<stri ...

  4. HDU 1984 ZOJ 2987 Misspelling(模拟)

    题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1984 ZOJ:http://acm.zju.edu.cn/onlinejudge/showP ...

  5. ZOJ 3829 Known Notation(贪心)题解

    题意:给一串字符,问你最少几步能变成后缀表达式.后缀表达式定义为,1 * 1 = 1 1 *,题目所给出的字串不带空格.你可以进行两种操作:加数字,交换任意两个字符. 思路:(不)显然,最终结果数字比 ...

  6. ZOJ 3829 Known Notation(贪心)

    题目链接 题意 :给你一个字符串,但是空格丢失,问你需要多少次操作能够让这个字符串可以看成合法的逆波兰式,例如12*3*4不是合法的逆波兰式,但是12*34*可以看成1 2*34*是正确的逆波兰式. ...

  7. zoj 3327 Friend Number 模拟题

    一年的省赛题目. 先容我骂一下,这题目有病吧,我调试了一个下午+晚上,好不容易才顺利A了,真是坑. 比赛中能做出来的那绝对是厉害啊!!. 我的思路,方法可能有笨: 1.首先判断下有几个0,有一个0的话 ...

  8. ZOJ3826 Hierarchical Notation(14牡丹江 H) 树套树

    题意:给你一个嵌套字典,询问字典的键值 ,输出字典的值. 解题思路:我的想法是字典树套字典树,因为指针的大小为8 字节 所以动态字典树会超内存,开始以为不能静态,后来发现静态实现也挺简单.所以又改成静 ...

  9. zoj 1851 Code Formatter 模拟

    题目链接:http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=2851 题意:给出一段代码,统计'\t'和后缀空格的个数,有一个地方要 ...

最新文章

  1. 影像组学视频学习笔记(9)-T检验(T-test)理论及示例、Li‘s have a solution and plan.
  2. gameplay理解
  3. 算法:搜索插入的位置
  4. qq飞车登陆服务器无响应,qq飞车手游进不去怎么回事 为什么进不去游戏
  5. BZOJ1798: [Ahoi2009]Seq 维护序列seq
  6. MySQL 高级 - 触发器 - 创建及应用
  7. java 在界面上画一个时钟_编写程序显示一个时钟 - javaCoder的个人页面 - OSCHINA - 中文开源技术交流社区...
  8. sap abap开发从入门到精通_SAP开发-ABAP数据字典(锁)
  9. centos7安装samba服务器
  10. html5 内嵌网页_如何分析并优化网页的性能?新梦想软件测试
  11. numpy 常用工具函数 —— np.bincount/np.average
  12. oracle 尝试分配内存不足,ORA-04030: 在尝试分配...字节(...)时进程内存不足的原因分析解决方法...
  13. 区块链大咖谈之陈昌:联盟链和公有链混合架构如何实现?
  14. 烧录esp32 并用oled显示
  15. Python 爬虫实战,模拟登陆爬取数据
  16. 方阵循环右移c语言,C语言第二次实验报告 - osc_zfz30hgc的个人空间 - OSCHINA - 中文开源技术交流社区...
  17. php花朵飘落特效,【新年气象】WordPress 主题添加花瓣飘落特效
  18. 牛客网sql练习题解(22-32)
  19. java二进制视频_Java二进制概念(含视频)
  20. python程序员教你用微信给对方定位!你说回家!却还在外面鬼混?

热门文章

  1. click quickstart
  2. opencv 数学操作
  3. list 操作 java_Java,List操作技巧
  4. 如何使用并解释通过 vSAN 监测收集的性能统计信息 (2064240)
  5. 实现裸金属服务器的安全微分段
  6. 未将更新安装在此计算机上,Win7用户注意!7月前没安装这个更新包,将不能再使用更新功能!...
  7. Diango 框架起步
  8. Exchange2010 SP1及以上邮箱的数据导出与导入
  9. json字符串使用注意问题
  10. nutch2.3.1 scoring-opic 插件url评分为0 问题