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 学习入门(20)—— 循环

    1. for 循环 for循环需要预先设定好循环的次数(n),然后执行隶属于for的语句n次. 基本构造是 for 元素 in 序列: statement 举例来说,我们编辑一个叫forDemo.py ...

  2. boa-0.94.13:Hello CGI

    CGI是什么 CGI全称是CommonGateway Interface,简称CGI,中文名叫做通用网关接口. CGI程序就是符合CGI接口规范的程序,相对于WebServer来说也叫外部程序. CG ...

  3. hdc和hwnd的区别

    句柄概念在WINDOWS编程中是一个很重要的概念,在许多地方都扮演着重要的角色.但由此而产生的句柄概念也大同小异,比如:<<Microsoft   Windows   3   Develo ...

  4. 临界段CCriticalSection的使用

    类CCriticalSection的对象表示一个“临界区”,它是一个用于同步的对象,同一时刻仅仅同意一个线程存取资源或代码区.临界区在控制一次仅仅有一个线程改动数据或其他的控制资源时很实用.比如,在链 ...

  5. LeetCode--Best Time to Buy and Sell Stock (贪心策略 or 动态规划)

    Best Time to Buy and Sell Stock Total Accepted: 14044 Total Submissions: 45572My Submissions Say you ...

  6. Hibernate核心接口

    1.Configuration接口 Configuration负责管理Hibernate的配置信息. 2,SessionFactory接口 SessionFactory负责创建Session实例,能够 ...

  7. [黑马程序员] I/O

    ---------------------- ASP.Net+Android+IO开发..Net培训.期待与您交流! ---------------------- 0. IO流概述: Java对数据的 ...

  8. dwz+jquery+fileupload+springmvc实现文件上传 及图片预览

    1 前台jsp:文件的上传利用了iframe实现局部刷新功能.使用了apache的fileupload组件,用到的jar: commons-fileupload.jar,commons-io.jarD ...

  9. poj 1845 POJ 1845 Sumdiv 数学模板

    筛选法+求一个整数的分解+快速模幂运算+递归求计算1+p+p^2+````+p^nPOJ 1845 Sumdiv求A^B的所有约数之和%9901 */#include<stdio.h>#i ...

  10. Qt移动版优化后台云服务、支持跨平台开发

    http://mp.weixin.qq.com/mp/appmsg/show?__biz=MjM5MDE0Mjc4MA==&appmsgid=10000461&itemidx=2&am ...