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. boost.asio系列——io_service

    IO模型 io_service对象是asio框架中的调度器,所有异步io事件都是通过它来分发处理的(io对象的构造函数中都需要传入一个io_service对象). asio::io_service i ...

  3. mfc控件与其对应的对象的关联方法

    对话框的控件与其对应类的对象相关联:(两种方法) (1)      通过CWnd::DoDataExchange函数进行关联: 用VC++6.0的MFC ClassWizard中的Member Var ...

  4. python实现PKCS5Padding

    python实现PKCS5Padding     python实现PKCS5Padding    2008-09-21     请参考    ssl-3-padding-mode    php的加密函 ...

  5. ThinkPhp学习08

    原文:ThinkPhp学习08 一.普通查询方式 a.字符串 $arr=$m->where("sex=0 and username='gege'")->find(); ...

  6. 百度GPSutil

    ================================================= package com.qcar.benz.biz.common; import com.aliba ...

  7. NginX issues HTTP 499 error after 60 seconds despite config. (PHP and AWS)

    FROM: http://stackoverflow.com/questions/15613452/nginx-issues-http-499-error-after-60-seconds-despi ...

  8. 第m个全排列

    #include<stdio.h> #include<string.h> int flag,n,m; ],sum,vis[]; void dfs(int k) { ) retu ...

  9. 取CPU序列号,获取网卡,取硬盘系列号,获取目录下的文件,强制删除目录

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  10. CF 514C(hash)

    传送门:Watto and Mechanism 题意:输入a个字符串和b个待检测字符串.问待检测字符串是否可以由某个已知字符串改变且只改变一个字母得到. 分析:字符串hash,枚举待测字符串每一位进行 ...