zoj3826 DFS

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5380

#include<iostream>
#include<algorithm>
#include<string>
#include<map>//int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0};
#include<set>//int gcd(int a,int b){return b?gcd(b,a%b):a;}
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<stdlib.h>
#include<cstdio>
#define mod 1e9+7
#define ll long long
using namespace std;
map<ll,pair<int,int> > r;
string x[1001];
string y;
int w;
int idx(char c){
	if(c>='0'&&c<='9')
		return c-'0';
	else if(c>='A'&&c<='Z')
		return c-'A'+10;
	else if(c=='a'&&c<='z')
		return c-'a'+36;
	else
		return 62;
}
void dfs(ll p){
	ll tmp=p;
	while(y[w]!='}'){
		w++;
		if(y[w]=='}')
			return;
		p=tmp;
		while(y[w]!=':'){
			p=p*60+idx(y[w]);
			w++;
		}
		w++;
		int l=w;
		if(y[w]=='{')
			dfs(p*60+62);
		else{
			while(y[w+1]!='}'&&y[w+1]!=',')
				w++;
		}
		r[p]=make_pair(l,w);
		w++;
	}
}
int main(){
	int t;
	cin>>t;
	while(t--){
		r.clear();
		w=0;
		cin>>y;
		dfs(0);
		int n;
		cin>>n;
		for(int i=0;i<n;++i){
			cin>>x[i];
			ll s=0;
			for(int j=0;j<x[i].length();++j)
				s=s*60+idx(x[i][j]);
			if(r.count(s)){
				for(int j=r[s].first;j<=r[s].second;++j)
					cout<<y[j];
				cout<<endl;
			}
			else
				cout<<"Error!"<<endl;
		}
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值