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的更多相关文章

  1. 2014牡丹江——Known Notation

    题目链接 题意: 输入一个长度不超过1000的字符串,包含数字(1-9)和星号(*).字符串中的空格已经丢失,所以连起来的数字串能够看成很多分开的数.也能够看成连续的数,即能够随意加入空格. 如今有两 ...

  2. 2014 牡丹江区域赛 B D I

    http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=358 The 2014 ACM-ICPC Asia Mudanj ...

  3. ZOJ 3826 Hierarchical Notation 模拟

    模拟: 语法的分析 hash一切Key建设规划,对于记录在几个地点的每个节点原始的字符串开始输出. . .. 对每一个询问沿图走就能够了. .. . Hierarchical Notation Tim ...

  4. zoj3826 Hierarchical Notation (字符串模拟)

    Hierarchical Notation Time Limit: 2 Seconds      Memory Limit: 131072 KB In Marjar University, stude ...

  5. 2014牡丹江区域赛H(特里)ZOJ3826

    Hierarchical Notation Time Limit: 2 Seconds      Memory Limit: 131072 KB In Marjar University, stude ...

  6. [2014 Regional]牡丹江 H Hierarchical Notation 做题记录

    主妇:老年人谁是炮灰牡丹江,我们的团队只是做同步大赛 他决定开爆震H什么时候,A 5min 1Y.I在该限制后,纠结了很久30min+ 1Y,神继续承担各种位置卡D在,hpp见B我认为这是非常熟悉的研 ...

  7. ZOJ 3829 Known Notation (2014牡丹江H称号)

    主题链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=5383 Known Notation Time Limit: 2 S ...

  8. 2014牡丹江K Known Notation

    Known Notation Time Limit: 2 Seconds      Memory Limit: 65536 KB Do you know reverse Polish notation ...

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

随机推荐

  1. Python 链接MysqlDB

    下载安装MySQLdb <1>linux版本 http://sourceforge.net/projects/mysql-python/ 下载,在安装是要先安装setuptools,然后在 ...

  2. MonkeyRunner 学习

    monkeyrunner 本文档中包含 一个简单的monkeyrunner示例程序 monkeyrunner API简介 运行monkeyrunner monkeyrunner内建帮助 使用插件扩展m ...

  3. v$lock 视图访问慢解决方法

    V$ 视图访问慢 --解决方法 分析:可能是有数据字典统计信息过久,造成. exec dbms_stats.gather_fixed_objects_stats; ------收集所有数据字典的fix ...

  4. poj 3211 Washing Clothes(背包)

    很不错的01背包!!! 不过有点疑问!!!(注释) #include <algorithm> #include<stdio.h> #include<string.h> ...

  5. Delphi访问活动目录

    活动目录Active Directory是用于Windows Server的目录服务,它存储着网络上各种对象的有关信息,并使该信息易于管理员和用户查找及使用.Active Directory使用结构化 ...

  6. pathload --有效的网络带宽估计方法

    上一篇博客简述了现行的带宽估计的方法,分类,以及一些问题. 见:http://blog.csdn.net/ice110956/article/details/11071969 上文列出了13种现行的方 ...

  7. linux c正则

    c 正则 --------------------------------------------------    标准的C和C++都不支持正则表达式,但有一些函数库可以辅助C/C++程序员完成这一 ...

  8. 使用CUNIT测试

    使用CUNIT测试 一:概述 CUnit是一个c语言的单元测试框架,它是以静态链接库的形式,连接到用户代码中的,主要的功能就是提供了语义丰富的断言和多种测试结果输出接口,可以方便地生成测试报告. 但是 ...

  9. ThinkPhp学习09

    原文:ThinkPhp学习09 三.区间查询 $data['id']=array(array('gt',4),array('lt',10));//默认关系是 and 的关系 //SELECT * FR ...

  10. 14.3.4 Phantom Rows 幻影行

    14.3.4 Phantom Rows 幻影行 所谓的幻读为发生在一个事务 当相同的查询产生不同的结果集在不同的时间. 比如,如果一个SELECT被执行2次, 但是第2次返回的记录不是第一次返回的记录 ...