2014牡丹江——Hierarchical Notation
problemId=5380" style="background-color:rgb(51,255,51)">题目链接
字符串模拟
const int MAXN = 2000000; char ipt[MAXN], t[MAXN];
int f[MAXN], len, to[MAXN];
map<string, string> mp[MAXN];
string x, key, ans;
string i2s(int n)
{
string ret = "";
if (n == 0)
ret += '0';
else
{
while (n)
{
ret += n % 10 + '0';
n /= 10;
}
}
ret += '*';
reverse(ret.begin(), ret.end());
return ret;
}
int s2i(string& s)
{
int ret = 0;
FF(i, 1, s.length())
ret = ret * 10 + s[i] - '0';
return ret;
} void fun_f()
{
stack<int> sk;
sk.push(0);
int cnt = 0;
REP(i, len)
{
if (ipt[i] == '{')
{
sk.push(++cnt);
f[i] = cnt;
to[f[i]] = i;
}
else if (ipt[i] == '}')
{
sk.pop();
f[i] = sk.top();
}
}
} void fun_ipt()
{
int state = 0, lv = 0, nxt;
REP(i, len)
{
switch (ipt[i])
{
case '\"':
if (state == 0 || state == 2)
x = "\"";
else if (state == 1)
key = x + '\"';
else
mp[lv][key] = x + '\"';
state = (state + 1) % 4;
break;
case '{':
nxt = f[i];
if (state == 2)
{
mp[lv][key] = i2s(nxt);
state = 0;
}
lv = nxt;
break;
case '}':
lv = f[i];
break;
case ':' || ',':
break;
default:
x += ipt[i];
}
}
} void fun_case()
{
int state = 0, lv = 0, n;
RI(n);
REP(kase, n)
{
bool ok = true;
state = 0, lv = 1;
RS(t);
len = strlen(t);
REP(i, len)
{
if (t[i] == '\"')
{
if (state == 0)
x = '\"';
else
{
x += '\"';
if (mp[lv].count(x) == 0)
{
ok = false;
break;
}
}
ans = mp[lv][x];
state = !state;
}
else if (t[i] == '.')
{
if (ans[0] != '*')
{
ok = false;
break;
}
lv = s2i(ans);
}
else
x += t[i];
}
if (ok)
{
if (ans[0] == '*')
{
int i = to[s2i(ans)], cnt = 0;
while (true)
{
if (ipt[i] == '{')
cnt++;
else if (ipt[i] == '}')
{
if (--cnt == 0)
break;
}
putchar(ipt[i]);
i++;
}
puts("}");
}
else
puts(ans.c_str());
}
else
puts("Error!");
}
} int main()
{
int T;
RI(T);
while (T--)
{
REP(i, MAXN)
mp[i].clear(); RS(ipt);
len = strlen(ipt);
fun_f();
fun_ipt();
fun_case();
}
return 0;
}
2014牡丹江——Hierarchical Notation的更多相关文章
- 2014牡丹江——Known Notation
题目链接 题意: 输入一个长度不超过1000的字符串,包含数字(1-9)和星号(*).字符串中的空格已经丢失,所以连起来的数字串能够看成很多分开的数.也能够看成连续的数,即能够随意加入空格. 如今有两 ...
- 2014 牡丹江区域赛 B D I
http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=358 The 2014 ACM-ICPC Asia Mudanj ...
- ZOJ 3826 Hierarchical Notation 模拟
模拟: 语法的分析 hash一切Key建设规划,对于记录在几个地点的每个节点原始的字符串开始输出. . .. 对每一个询问沿图走就能够了. .. . Hierarchical Notation Tim ...
- zoj3826 Hierarchical Notation (字符串模拟)
Hierarchical Notation Time Limit: 2 Seconds Memory Limit: 131072 KB In Marjar University, stude ...
- 2014牡丹江区域赛H(特里)ZOJ3826
Hierarchical Notation Time Limit: 2 Seconds Memory Limit: 131072 KB In Marjar University, stude ...
- [2014 Regional]牡丹江 H Hierarchical Notation 做题记录
主妇:老年人谁是炮灰牡丹江,我们的团队只是做同步大赛 他决定开爆震H什么时候,A 5min 1Y.I在该限制后,纠结了很久30min+ 1Y,神继续承担各种位置卡D在,hpp见B我认为这是非常熟悉的研 ...
- ZOJ 3829 Known Notation (2014牡丹江H称号)
主题链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=5383 Known Notation Time Limit: 2 S ...
- 2014牡丹江K Known Notation
Known Notation Time Limit: 2 Seconds Memory Limit: 65536 KB Do you know reverse Polish notation ...
- ACM学习历程——ZOJ 3829 Known Notation (2014牡丹江区域赛K题)(策略,栈)
Description Do you know reverse Polish notation (RPN)? It is a known notation in the area of mathema ...
随机推荐
- linux kill进程和子进程小trick
我们的hive web是调用polestar restful service(https://github.com/lalaguozhe/polestar-1)来执行具体的hive或者s ...
- js之checkbox的代码全选/全不选,使用id获取元素,而不是name
每当有多个选项的时候,都会有一种想法是:全选,全不选,如果子选项有被选,父选项也得被选. 注意:这里是根据id来获取元素的,但是不能直接用getElementById,因为那只能返回一个,而不是集合. ...
- Mahout-Pearson correlation的实现
计算公式: 并通过以下代码对Mahout in Action的结果进行了验证: 代码例如以下: ` package com.example.mahout; public class TestColl ...
- Swift - 让StoryBoard设计视图,程序运行时都使用横屏形式
1,运行时横屏 将项目属性“General”->“DeviceOritentation”的Portrait复选框去掉 2,storyboard设计视图横屏 在storyboard中,单击中间界面 ...
- HDU 2098 分拆素数和(素数)
HDU 2098 分拆素数和(素数) http://acm.hdu.edu.cn/showproblem.php?pid=2098 题意: 给你一个偶数,问你这个偶数有多少种方式能由两个不同的素数构成 ...
- google 搜索url详解
www.google.com [http://www.google.cn/search?q=112&hl=zh-CN&client=aff- 360daohang&hs=yhE ...
- 获取sina,baidu,google财经历史和实时股票数据接口
实时股票数据接口 股票数据的获取目前有如下两种方法可以获取:1. http/javascript接口取数据2. web-service接口1.http/javascript接口取数据1.1Sina股票 ...
- cannot load supported formats intellij 解决的方法
http://stackoverflow.com/questions/20797443/intellij-idea-subversion-checkout-error http://stackover ...
- iOS_10_tableView的简单使用_红楼十二钗
终于效果图: 方式1,用字典数组 BeyondViewController.h // // BeyondViewController.h // 10_tableView // // Created b ...
- 浅谈 Python 程序和 C 程序的整合
源地址:http://www.ibm.com/developerworks/cn/linux/l-cn-pythonandc/ 概览 Python 是一种用于快速开发软件的编程语言,它的语法比较简单, ...