这是我的trie代码
//Think twice,code once
#define ll long long
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int N=1e4+10,M=1e5+10;
struct node{
bool wrd,rep;
int to[26];
}trie[N*50];
int n,m;
int triecnt,rt;
int leaf[N];
//Fast IO
int ss[20],topp;
inline int read(){//
register int xx=0,ff=1,cc=getchar();//
while(!isdigit(cc)){if(cc=='-') ff=-1;cc=getchar();}
while(isdigit(cc)) xx=xx*10+cc-48,cc=getchar();
return xx*ff;
}
inline void write(int xx){//
if(!xx){
putchar(48);
return;
}
if(xx<0) putchar('-'),xx=-xx;
while(xx) ss[++topp]=xx%10,xx/=10;
while(topp) putchar(ss[topp]+48),--topp;
}
//Fast Function
inline int Abs(int xx){return xx>0?xx:-xx;}//
inline int Max(int xx,int yy){return xx>yy?xx:yy;}//
inline int Min(int xx,int yy){return xx<yy?xx:yy;}//
inline void Swap(int& xx,int& yy){xx^=yy,yy^=xx,xx^=yy;}//
inline int ins(char* s){
int pos=rt;
while(*s){
if(!pos) pos=++triecnt;
pos=trie[pos].to[*s-'a'];
++s;
}
trie[pos].wrd=true;
return pos;
}
inline int query(char* s){
int pos=rt;
while(*s){
if(!pos) return 0;
pos=trie[pos].to[*s-'a'];
++s;
}
return pos;
}
int main(){
n=read();
for(int i=1;i<=n;++i){
string s;
scanf("%s",&s);
leaf[i]=ins(s);//61
}
m=read();
for(int i=1;i<=m;++i){
string s;
scanf("%s",&s);
int p=query(s);//67
if(trie[p].wrd)
if(!trie[p].rep) printf("OK\n"),trie[p].rep=true;
else printf("REPEAT\n");
else printf("WRONG\n");
}
return 0;
}
第61,67行爆CE(代码里有标出)
是参数设置有问题吗,珂是明明记得string是char数组
还请dalao解释
(另外请dalao不要喷leaf数组没用,我无聊开的)