ZOJ 3826
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
赛后看见别人补这个题,我便也补,其实场上没有看这个题,听说是到模拟,我觉得正解应该就是字符串处理来模拟数据库,然而这个题可以更简单,由于数据少,10000条key,所以hush便出现重的几率很小,看见大家都是字符串+hush水的,我也这么做的,总之,这样做简单啊。。。
注意边界处理
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define repd(i, a, b) for(int i = b; i >= a; i--)
#define sfi(n) scanf("%d", &n)
#define sfl(n) scanf("%lld", &n)
#define pfi(n) printf("%d\n", n)
#define pfl(n) printf("%lld\n", n)
#define MAXN 1000005
#define BASE 131
char s[MAXN];
map<ll, pair<int, int> > ma;
ll id(char c)
{
return ((ll)c) % BASE;
}
int p;
void Create(ll f)
{
while(s[p] != '}')
{
if(s[++p] == '}') return ;
ll t = f;
while(s[p] != ':')
{
t = t * BASE + id(s[p]);
p++;
}
int st = ++p;
if(s[p] == '{')
{
Create(t * BASE + id('.'));
}
else
{
while(s[p] != ',' && s[p] != '}') p++;
}
if(s[p] == '}')
ma[t] = pair<int, int>(st, p + );
else ma[t] = pair<int, int>(st, p);
//cout<<t<<endl;
}
return ;
} int main()
{
int T;
sfi(T);
while(T--)
{
ma.clear();
scanf("%s", s);
int n;
char t[MAXN];
p = ;
Create();
sfi(n);
repu(i, , n)
{
scanf("%s", t);
ll key = ;
int len = strlen(t);
repu(j, , len) key = key * BASE + id(t[j]);
if(!ma.count(key))
{
printf("Error!");
}
else
{
pair<int, int> tt = ma[key];
repu(j, tt.first, tt.second + ) printf("%c", s[j]);
}
puts("");
}
}
return ;
}
ZOJ 3826的更多相关文章
- ZOJ 3826 Hierarchical Notation 模拟
模拟: 语法的分析 hash一切Key建设规划,对于记录在几个地点的每个节点原始的字符串开始输出. . .. 对每一个询问沿图走就能够了. .. . Hierarchical Notation Tim ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
- ZOJ Problem Set - 1001 A + B Problem
ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...
- zoj 1788 Quad Trees
zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...
随机推荐
- 【VB6笔记-01】 读取Excel绑定到DataGrid
Private Sub cmdOpen_Click() CommonDialog1.Filter = "Excel???t(*.xlsx)|*.xlsx" CommonDialog ...
- 小题精炼-----初试C语言
毫无疑问, 这个又是给新入门学C语言的小鲜肉准备的! 题解: 1. 直接两个循环就ok啦! 当初讲课的时候几乎讲过原题啦. 2. 直接 100的三次方就是1000000啦, 所以直接对某数的三次方开方 ...
- mysql概要(十)触发器
1触发器可监视增删改,并触发增删改操作. 针对一些逻辑关联密切的操作,而不必手动多次操作. 2.要素: 3.语法: 补充:mysql可以设置结束符,不必是“:”来结束标志,可使用 3.1简单的例子: ...
- dateTimePicker的使用,时间控件
<li> <label>促销时间<span class="imprt">*</span></label> <inp ...
- mysql 大数据量求平均值
需求是:对于一个设备,求一天内每个小时的平均值,一个月内每天的平均值,更通用的需求是,从起始时间到结束时间,每隔一段时间,求一个平均值.目前的解决策略是:在存储过程中进行处理,从起始时间到结束时间,切 ...
- jpeg了解
JPEG是一个压缩标准,又可分为标准 JPEG.渐进式JPEG及JPEG2000三种: ①标准JPEG:以24位颜色存储单个光栅图像,是与平台无关的格式,支持最高级 别的压缩,不过,这种压缩是有损耗的 ...
- iOS--获取输入字符的第一个字母(汉字则获取拼音的第一个字母)
- (NSString *)firstCharactor:(NSString *)aString { //转成了可变字符串 NSMutableString *str = [NSMutableStrin ...
- iOS——为Xcode编译POCO C++静态库
一.POCO C++ library简介 POCO C++ library是一个C++编写的跨平台库,主要实现网络连接.数据库管理以及服务器,适用于跨平台.嵌入式. 二.为Xcode编译POCO C+ ...
- HttpURLConnection请求接口
import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.DataOutputStream; ...
- Maven最佳实践:划分模块
http://juvenshun.iteye.com/blog/305865 ************************************* "分天下为三十六郡,郡置守,尉,监& ...