比赛 |
普及组2016模拟练习4 |
评测结果 |
AAAAAAAAAA |
题目名称 |
查字典 |
最终得分 |
100 |
用户昵称 |
_IOSTREAM_ |
运行时间 |
0.584 s |
代码语言 |
C++ |
内存使用 |
16.32 MiB |
提交时间 |
2016-11-17 20:39:45 |
显示代码纯文本
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
#define SIZE 16777216
char inbuf[SIZE],*HEAD=inbuf,*TAIL=inbuf;
#define getc() (HEAD==TAIL&&(TAIL=(HEAD=inbuf)+fread(inbuf,1,SIZE,stdin),HEAD==TAIL)?0:*HEAD++)
__inline__ __attribute((always_inline))
void read(int& ret){
register int ans=0;
register char CH;
while(CH=getc(),CH<48);
while(ans=ans*10+CH-48,CH=getc(),CH>47);
ret=ans;
}
__inline__ __attribute((always_inline))
void read(char *ch){
register char CH;
register int READITER=0;
while(CH=getc(),CH<65);
while(ch[READITER++]=CH,CH=getc(),CH>64);
ch[READITER]=0;
}
struct trie{
trie* next[26];
int data;
}root;
__inline__ __attribute((always_inline))
void insert(char *str,int &page){
register char ch;
trie *now=&root;
while(ch=*str++){
ch-=97;
if(now->next[ch]==0){
now->next[ch]=new trie;
now=now->next[ch];
for(register int i=0;i<26;i++)now->next[i]=0;
}else now=now->next[ch];
}
now->data=page;
}
__inline__ __attribute((always_inline))
trie* find(char *str){
register char ch;
trie *now=&root;
while(ch=*str++){
ch-=97;
if(now->next[ch]==0){
return 0;
}else now=now->next[ch];
}
return now;
}
int main(){
freopen("scanword.in","r",stdin);
freopen("scanword.out","w",stdout);
ios::sync_with_stdio(false);
register int n,p;
register char ch[105];
read(n);
for(register int i=0;i<n;i++){
read(ch);read(p);
insert(ch,p);
}
read(n);
for(register int i=0;i<n;i++){
read(ch);
cout<<find(ch)->data<<endl;
}
return 0;
}