您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: