ZOJ 3826 Hierarchical Notation

题目:

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[N],ss[N];
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;
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值