ZOJ 3826 Hierarchical Notation
2015-10-02 16:42
399 查看
题目:
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3826题意:
模拟python的字典保存,{"hm":"Edward","stu":{"stu01":"Alice","stu02":"Bob"}}
如上面这排就是hm代表Edward,stu代表{"stu01":"Alice","stu02":"Bob"}},stu.stu01代表Alice。
思路:
就是强行模拟,直接map<string,pair>会tle,要改成hash存入map,数据松,所以还是很好过的。代码:
#define N 2123456 int n,m; int flag,sum,ave,ans,res,len,ans1,ans2; char s ,ss ; map<int,pair<int,int> >mp; void dfs(int now) { while(s[res]!='}') { if(s[++res]=='}')return; int t=now; while(s[res]!=':')t=t*MOD+s[res++]; int x=++res; if(s[res]=='{')dfs(t*MOD+'.'); else while(s[res+1]!=',' && s[res+1]!='}')res++; mp[t]=make_pair(x,res);res++; } } int main() { int i,j,k,kk,t,x,y,z; scanf("%d",&k); while(k--) { scanf("%s",s); res=0;mp.clear(); dfs(0); scanf("%d",&n); for(i=0;i<n;i++) { scanf("%s",ss); y=strlen(ss); for(j=0,t=0;j<y;j++) t=t*MOD+ss[j]; if(mp.count(t)) { x=mp[t].first;y=mp[t].second; for(j=x;j<=y;j++)printf("%c",s[j]); printf("\n"); } else printf("Error!\n"); } } return 0; }
相关文章推荐
- 【nodemailer】 之邮件附件
- 非排序寻找从小到大第3400个数
- pch文件 解决每个文件都需要重复引入的问题
- Linux 命令 - tail: 打印文件的结尾部分
- 【 D3.js 入门系列 --- 0 】 简介及安装
- hdu1048 The Hardest Problem Ever
- 面试题24:二叉搜索树的后序遍历序列
- UVa12171 Sculpture
- ocp-39
- IOS动画效果
- MyISAM vs InnoDB 分析之一
- HDU 2070 Fibbonacci Number
- python-文件读取
- hdu 1429 状态搜索
- HashTable的实现原理分析
- ocp-38
- 进程间的通信(浅谈)
- ocp-37
- 【C语言】双向链表的实现
- awk 正则表达式、正则运算符详细介绍