Hierarchical Notation ZOJ
来源:互联网 发布:actor critic知乎 编辑:程序博客网 时间:2024/05/16 18:37
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.
There are multiple test cases. The first line of input contains an integer Tindicating 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.
<h4< dd="">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).
<h4< dd="">1{"hm":"Edward","stu":{"stu01":"Alice","stu02":"Bob"}}4"hm""stu""stu"."stu01""students"<h4< dd="">
"Edward"{"stu01":"Alice","stu02":"Bob"}"Alice"Error!
学了哈希的用法 把每一个字符串转换成一个数字来形成映射
还有就是里面找对应括号用到了深搜 遇到左括号就进入下一层搜索直到遇到右括号再回到上一层
map中的count用于返回key出现的次数 在map中只可能为0或1
#include <iostream>#include <map>#include <vector>#include <algorithm>#include<cstdio>using namespace std;const int maxn = 2000000;const int x=123;long long start;char s[maxn],op[maxn];typedef pair<int,int>pos;map<long long,pos>g;int idx(char ch){ if (ch >= '0' && ch <= '9') return ch - '0'; else if (ch >= 'A' && ch <= 'Z') return ch - 'A' + 10; else if (ch >='a' && ch <= 'z') return ch - 'a' + 36; else if (ch == '.') return 62; return 63;}void solve(long long u){ long long tmp=u; while(s[start]!='}') { start++; if(s[start]=='}') return ; u=tmp; while(s[start]!=':') u=u*x+idx(s[start++]); //确定Key值 int l=++start; //对应字符串的起始位置 if(s[start]=='{') solve(u*x+62LL); else while(s[start+1]!=','&&s[start+1]!='}') start++; g[u]=make_pair(l,start); start++; }}int main(){ int t; cin>>t; while(t--) { scanf("%s",s); g.clear(); start=0; solve(0); int q; scanf("%d",&q); for(int i=0;i<q;i++) { scanf("%s",op); long long tmp=0; for(int i=0;op[i]!='\0';i++) tmp=tmp*x+idx(op[i]); if(g.count(tmp)) //结果为0或1 { pos u=g[tmp]; //注意这个用法 for(int i=u.first;i<=u.second;i++) printf("%c",s[i]); printf("\n"); } else printf("Error!\n"); } } return 0;}
- ZOJ 3826 Hierarchical Notation
- ZOJ 3826 Hierarchical Notation
- ZOJ 3826Hierarchical Notation
- Hierarchical Notation ZOJ
- zoj 3826 Hierarchical Notation(模拟)
- zoj 3826 Hierarchical Notation(模拟)
- ZOJ 3826 Hierarchical Notation 模拟
- zoj 3826 Hierarchical Notation 模拟
- ZOJ 3826 Hierarchical Notation 模拟
- ZOJ-3826-Hierarchical Notation【哈希】
- zoj 3826 Hierarchical Notation(模拟)
- ZOJ 3826 Hierarchical Notation(2014 牡丹江 H,字符串模拟)
- ZOJ 3826 Hierarchical Notation(2014 牡丹江 D,概率DP)
- ZOJ 3826 Hierarchical Notation(2014 Asia Mudanjiang Regional Contest)
- ZOJ 3826 Hierarchical Notation(模拟-字符串处理)
- zoj3826 Hierarchical Notation
- ZOJ3826(Hierarchical Notation)
- ZOJ 3826 Hierarchical Notation(2014 牡丹江 B,树的直径+二分)
- python 网络爬虫学习笔记之beautifulsoup
- Opencv 视频处理
- Git存储原理简介
- VMware Workstation Pro14虚拟机破解版(附注册机+序列号+安装教程) 32/64位
- HTML5 音频,视频
- Hierarchical Notation ZOJ
- 什么是JWT
- HTTP状态码汇总
- nodejs中的流
- Java打飞机小游戏(附完整源码)
- Android中装饰者模式
- leetcode 617. Merge Two Binary Trees(C语言,二叉树求和,递归)53
- java 画数学函数图
- 3react初体验-1版本的选择