字典树
来源:互联网 发布:淘宝网电脑版登录 怎么 编辑:程序博客网 时间:2024/04/20 08:50
#include<cstdio>#include<cstring>using namespace std;#define id(x) x-'a';struct st{ int nex[26]; int f,t;}s[911999];int tot=1;char st[199];void insert(char ste[]){ int rt=0,len=strlen(ste); for(int i=0;i<len;i++) { int c=id(ste[i]); if(!s[rt].nex[c]) { s[rt].nex[c]=tot++; } rt=s[rt].nex[c]; } s[rt].f++;}int find(char ste[]){ int rt=0,len=strlen(ste); for(int i=0;i<len;i++) { int c=id(ste[i]); if(!s[rt].nex[c]) { return 0; } rt=s[rt].nex[c]; } if(s[rt].f) return 1; return 0;}int n,m;int main(){ scanf("%d",&n); scanf("%d",&m); for(int i=1;i<=n;i++) { scanf("%s",st); insert(st); } for(int i=1;i<=m;i++) { scanf("%s",st); int w=find(st); if(!w)printf("WRONG\n"); else if(w==1)printf("OK\n"); else printf("REPEAT\n") ; }}
1 1
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树。。
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 【综合知识】系分综合知识总结
- dev c++ opengl的配置
- Java虚拟机的垃圾回收和收集算法
- Vue组件
- jquery.nicescroll.js 滚动条插件 API
- 字典树
- android 圆形纯数字按钮
- 哪些硬件需要驱动程序在电脑中?
- 红黑树之删除节点
- Android 自定义view 随着刷新次数变多而变慢
- JavaWeb——MyBatis入门程序
- 欢迎使用CSDN-markdown编辑器
- 计算机中正数和负数原码、反码、补码的表示
- openCV下载地址