zoj3826 Hierarchical Notation
2015-03-21 17:38
281 查看
题意:一些结构体,键和值是字符串,有若干组询问,输入键,输出值。
分析:写一个递归函数,用把每一个键对应一个哈希值,对应的值为开始和结束下标。
分析:写一个递归函数,用把每一个键对应一个哈希值,对应的值为开始和结束下标。
#include<iostream> #include<cstdio> #include<cstring> #include<map> #include<cstring> #include<algorithm> #include<vector> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef pair<int,int> pii; char s[3000000]; char str[3000000]; ull p=17; ull mod=1000000000000007; map<ull,pii>mp; int b; int idx(char ch) { if(ch>='0'&&ch<='9') return ch-'0'; else if(ch>='a'&&ch<='z') return ch-'a'+10; else if(ch>='A'&&ch<='Z') return ch-'A'+36; else if(ch=='.') return 62; else return 63; } void dfs(ull u) { ull ans=u; while(s[b]!='}') { if(s[b]==':') { if(s[b+1]=='{') { int a=b+1; b+=2; dfs((ans*p+62)%mod); mp[ans]=pii(a,b); b++; if(s[b]=='}') break; else b++; } else { int a=b+1; while(s[b]!=','&&s[b]!='}') { b++; } mp[ans]=pii(a,b-1); if(s[b]=='}') break; else b++; } ans=u; } ans=(ans*p+idx(s[b]))%mod; b++; } } int main() { int t; scanf("%d",&t); int k; while(t--) { mp.clear(); scanf("%s",s); b=1; dfs(0); scanf("%d",&k); for(int i=0;i<k;i++) { scanf("%s",str); ull ans=0; int len=strlen(str); for(int i=0;i<len;i++) { ans=(ans*p+idx(str[i]))%mod; } if(mp.count(ans)) { for(int j=mp[ans].first;j<=mp[ans].second;j++) printf("%c",s[j]); printf("\n"); } else printf("Error!\n"); } } return 0; }
相关文章推荐
- ZOJ 3826 Hierarchical Notation 模拟
- ZOJ-3826-Hierarchical Notation【哈希】
- ZOJ 3826 Hierarchical Notation(2014 Asia Mudanjiang Regional Contest)
- ZOJ 3826 Hierarchical Notation(亚洲区域赛牡丹江站 字符串模拟)
- ZOJ 3826 Hierarchical Notation 模拟
- ZOJ 3826 Hierarchical Notation(2014 牡丹江 H,字符串模拟)
- ZOJ 3826 Hierarchical Notation(模拟-字符串处理)
- zoj 3826 Hierarchical Notation(模拟)
- zoj 3826 Hierarchical Notation(hash+dfs)
- ZOJ 3826 Hierarchical Notation
- ZOJ 3826 Hierarchical Notation(Mudanjiang 2014)(JSON解析模拟)
- ZOJ 3826 Hierarchical Notation
- ZOJ 3826 Hierarchical Notation(2014 牡丹江 B,树的直径+二分)
- zoj 3826 Hierarchical Notation(模拟)
- ZOJ 3826 Hierarchical Notation 模拟
- ZOJ 3826 Hierarchical Notation(2014 牡丹江 D,概率DP)
- zoj 3826 Hierarchical Notation(模拟)
- ZOJ 3826 Hierarchical Notation
- zoj 3826 Hierarchical Notation(模拟)
- ZOJ 3829 Known Notation