同问。。。
by wyhwyh @ 2018-12-22 20:16:30
```cpp
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
int n,m;
struct node{
char son[26];
bool end;
bool app;//had appeared
node()
{
memset(son,false,sizeof son);
end=0;
app=0;
}
}trie[800000];
int trie_size;
void build(char name[])
{
int l=strlen(name);
int u=0;
for(int i=0;i<l;++i)
{
int v=name[i]-'a';
if(!trie[u].son[v])
trie[u].son[v]=++trie_size;
u=trie[u].son[v];
}
trie[u].end=1;
}
void doit(char name[])
{
int l=strlen(name);
int u=0;
for(int i=0;i<l;++i)
{
int v=name[i]-'a';
if(!trie[u].son[v])
{
printf("WRONG\n");
return;
}
u=trie[u].son[v];
}
if(!trie[u].end)
{
printf("WRONG\n");
return;
}
if(trie[u].app)
{
printf("REPEAT\n");
return;
}
trie[u].app=1;
printf("OK\n");
}
int main()
{
char name[100];
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
scanf("%s",name);
build(name);
}
scanf("%d",&m);
for(int i=1;i<=m;++i)
{
scanf("%s",name);
doit(name);
}
return 0;
}
```
by wyhwyh @ 2018-12-22 20:16:47
# 有到了喜闻乐见的找不同时间了。。。
by wyhwyh @ 2018-12-23 14:41:33
```cpp
#include<cstdio>
#include<cstring>
using namespace std;
int n,m;
struct node{
int app;
char son[26];
bool end;
node()
{
app=0;
memset(son,false,sizeof son);
end=0;
}
}trie[800000];
int trie_size=0;
void build(char *s)
{
int l=strlen(s);
int u=0,v;
for(int i=0;i<l;++i)
{
v=s[i]-'a';
if(!trie[u].son[v])
trie[u].son[v]=++trie_size;
u=trie[u].son[v];
}
trie[u].end=1;
}
int doit(char *s)
{
int l=strlen(s);
int u=0,v;
for(int i=0;i<l;++i)
{
v=s[i]-'a';
if(!trie[u].son[v])
return 3;
u=trie[u].son[v];
}
if(!trie[u].end)
return 3;
if(!trie[u].app)
{
trie[u].app++;
return 1;
}
return 2;
}
int main()
{
char name[100];
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
scanf("%s",name);
build(name);
}
scanf("%d",&m);
for(int i=1;i<=m;++i)
{
scanf("%s",name);
int f=doit(name);
if(f==1)
puts("OK");
else if(f==2)
puts("REPEAT");
else if(f==3)
puts("WRONG");
}
return 0;
}
```
10分,9个点re
by wyhwyh @ 2018-12-23 14:42:21
```cpp
#include<cstdio>
#include<cstring>
using namespace std;
int n,m;
struct node{
int cnt;
int son[26];
bool have;
node(){
cnt=0;
memset(son,false,sizeof son);
have=false;
}
}trie[800000];
int num=0;
void insert(char *s)
{
int v,len=strlen(s);
int u=0;
for(int i=0;i<len;i++)
{
v=s[i]-'a';
if(!trie[u].son[v])
trie[u].son[v]=++num
;
u=trie[u].son[v];
}
trie[u].have=1;
}
int find(char *s)
{
int v,u=0,len=strlen(s);
for(int i=0;i<len;i++)
{
v=s[i]-'a';
if(!trie[u].son[v])return 3;
u=trie[u].son[v];
}
if(!trie[u].have)return 3;
if(!trie[u].cnt)
{
trie[u].cnt++;
return 1;
}
return 2;
}
int main()
{
char name[100];
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
scanf("%s",name);
insert(name);
}
scanf("%d",&m);
for(int i=1;i<=m;++i)
{
scanf("%s",name);
int p=find(name);
if(p==1)
puts("OK");
else if(p==2)
puts("REPEAT");
else if(p==3)
puts("WRONG");
}
return 0;
}
```
题解:AC 100分
by wyhwyh @ 2018-12-23 14:42:54
@[我醉了](/space/show?uid=69146) dalao帮忙看看呗。。。
by wyhwyh @ 2018-12-23 14:43:48
# 终于A了,不容易呀!!!
```cpp
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
int n,m;
struct node{
int son[100];
bool end;
bool app;//had appeared
}trie[800000];
int trie_size;
char name[51];
void build()
{
int l=strlen(name);
int u=0;
for(int i=0;i<l;++i)
{
int v=name[i]-'a';
if(!trie[u].son[v])
trie[u].son[v]=++trie_size;
u=trie[u].son[v];
}
trie[u].end=1;
}
void doit()
{
int l=strlen(name);
int u=0;
for(int i=0;i<l;++i)
{
int v=name[i]-'a';
if(!trie[u].son[v])
{
printf("WRONG\n");
return;
}
u=trie[u].son[v];
}
if(!trie[u].end)
{
printf("WRONG\n");
return;
}
if(trie[u].app)
{
printf("REPEAT\n");
return;
}
trie[u].app=1;
printf("OK\n");
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
memset(name,false,sizeof name);
scanf("%s",name);
build();
}
scanf("%d",&m);
for(int i=1;i<=m;++i)
{
memset(name,false,sizeof name);
scanf("%s",name);
doit();
}
return 0;
}
```
发一波代码帮助一下和我一样蒻的萌新们(当然,可能没有我这么蒻的了)。。。
by wyhwyh @ 2018-12-23 15:49:46
@[陈星卿的笔](/space/show?uid=109407) 你把s数组的char类型改成int就行了。。。
by wyhwyh @ 2018-12-23 15:56:01
写错了,应该是trie数组【滑稽】
by wyhwyh @ 2018-12-23 15:57:50
全程自己说话。。。。
by 我醉了 @ 2018-12-23 18:39:47