大国重器2008
2021-01-22 21:26P2580 于是他错误的点名开始了(小白求救c++)
#include <iostream>
using namespace std;
const int maxn = 1e+5;
struct node {
char c;
bool end;
int num;
int son[26];
}trie[maxn];
int n, m, cnt = 1;
int index(char c) {
return c - 'a';
}
void and_trie(string& str) {
int cur = 1;
int len = str.length();
for (int i = 0; i < len; i++) {
if (trie[cur].son[index(str[i])] == 0) { // 取到每一个字符
++cnt;
trie[cur].son[index(str[i])] = cnt;
}
cur = trie[cur].son[index(str[i])];
}
trie[cur].end = true;
}
void query_trie(string& str) {
int cur = 1;
int len = str.length();
for (int i = 0; i < len; i++) {
if (trie[cur].son[index(str[i])] == 0) {
cout << "WRONG" << endl;
return;
}
cur = trie[cur].son[index(str[i])];
}
if (trie[cur].end) {
if (trie[cur].num == 0) {
cout << "OK" << endl;
trie[cur].num++;
} else {
cout << "REPEAT" << endl;
}
} else {
cout << "WRONG" << endl;
}
return;
}
int main() {
cin >> n;
string tmp;
for (int i = 1; i <= n; i++) {
cin >> tmp;
and_trie(tmp);
}
cin >> m;
for (int i = 1; i <= m; i++) {
cin >> tmp;
query_trie(tmp);
}
return 0;
}

- 点赞
- 回答
- 收藏
- 复制链接分享
2条回答
为你推荐
- BulletPHP框架和Firebase / JWT - 检查令牌错误
- rest
- api
- jwt
- php
- 1个回答
- 点名时间这个网站是用什么语言开发的?
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 0个回答
- ejb中spring代理struts,action请求找不到,can not instance for path
- 企业应用
- 0个回答
- 基于web学生签到系统的源码
- 源码
- javascript
- web
- 管理
- sql
- 4个回答
- 求助:java编写点名器
- java
- 3个回答
换一换