当前位置:网站首页>洛谷P2580 于是他错误的点名开始了
洛谷P2580 于是他错误的点名开始了
2022-08-11 04:00:00 【CLH_W】
题目背景
XS中学化学竞赛组教练是一个酷爱炉石的人。
他会一边搓炉石一边点名以至于有一天他连续点到了某个同学两次,然后正好被路过的校长发现了然后就是一顿欧拉欧拉欧拉(详情请见已结束比赛 CON900)。
题目描述
这之后校长任命你为特派探员,每天记录他的点名。校长会提供化学竞赛学生的人数和名单,而你需要告诉校长他有没有点错名。(为什么不直接不让他玩炉石。)
输入格式
第一行一个整数 nn,表示班上人数。
接下来 nn 行,每行一个字符串表示其名字(互不相同,且只含小写字母,长度不超过 5050)。
第 n+2n+2 行一个整数 mm,表示教练报的名字个数。
接下来 mm 行,每行一个字符串表示教练报的名字(只含小写字母,且长度不超过 5050)。
输出格式
对于每个教练报的名字,输出一行。
如果该名字正确且是第一次出现,输出 OK,如果该名字错误,输出 WRONG,如果该名字正确但不是第一次出现,输出 REPEAT。
输入输出样例
输入 #1复制
5
a
b
c
ad
acd
3
a
a
e
输出 #1复制
OK
REPEAT
WRONG
说明/提示
对于 40%40% 的数据,n\le 1000n≤1000,m\le 2000m≤2000。
对于 70%70% 的数据,n\le 10^4n≤10
4
,m\le 2\times 10^4m≤2×10
4
。
对于 100%100% 的数据,n\le 10^4n≤10
4
,m≤10^5m≤10
5
。
\text{upd 2022.7.30}upd 2022.7.30:新增加一组 Hack 数据。
上代码:
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <cmath>
#define re register
struct Trie{
bool count; int next[26]; bool exist; //exist表示此处是否为一个单词;count表示此单词是否已被查询。
}a[500100]; int top(1);
char str[60]; int n, m;
char buf[10000], *p = buf, *end = buf; int lent; //不要在意读入优化,使用scanf("%d") 与 scanf("%s") 对应相应读入即可。
inline char getChar() {
if(p == end) {
if(feof(stdin)) return '\0';
p = buf, end = buf + fread(buf, 1, 10000, stdin);
}
return *(p++);
}
inline void getString(char* str) {
lent = 0; char _c;
while (!isalpha(_c = getChar()));
do str[lent++] = _c;
while (isalpha(_c = getChar()));
str[lent] = '\0';
return ;
}
inline void getNum(int& x) {
x = 0; char c;
while(!isdigit(c = getChar()));
do x = x * 10 + (c - '0');
while(isdigit(c = getChar()));
return ;
}
inline void Trie_insert() {
//普通insert操作,将字符串一一加入字典中
int num(0), root = 1;
for (re int i = 0; str[i]; ++i) {
num = str[i] - 'a';
if(!a[root].next[num]) a[root].next[num] = ++top;
root = a[root].next[num];
}
a[root].exist = true;
return ;
}
inline int Trie_search() {
//普通search操作,查询是否存在该字符串
int num(0), root = 1;
for (re int i = 0; str[i]; ++i) {
num = str[i] - 'a';
if(!a[root].next[num]) return 0; //若无法查询到后继的字母,直接退出
root = a[root].next[num];
}
if(!a[root].exist) return 0; //若此处不存在字符串,返回“WRONG”
else if(a[root].count) return 2; //若此处字符串已被查询,返回“REPEAT”
a[root].count = true; //若以上均不满足,说明合法
return 1; //此字符串标记为已查询,返回“OK”
}
int main() {
getNum(n);
for (re int i = 1; i <= n; ++i) {
//插入
memset(str, 0, sizeof str);
getString(str);
Trie_insert();
}
getNum(m);
scanf("%d", &m);
for (re int i = 1; i <= m; ++i) {
//查询
memset(str, 0, sizeof str);
getString(str);
int tmp = Trie_search();
if(tmp == 0) printf("WRONG\n"); //分类讨论
else if(tmp == 1) printf("OK\n");
else if(tmp == 2) printf("REPEAT\n");
}
return 0;
}
边栏推荐
- 洛谷P4032 火锅盛宴
- "110 Balanced Binary Tree Judgment" in leetCode's 14-day binary tree series
- CTO said that the number of rows in a MySQL table should not exceed 2000w, why?
- 【FPGA】day20-I2C读写EEPROM
- Audio codec, using FAAC to implement AAC encoding
- The FTP error code list
- Build Zabbix Kubernetes cluster monitoring platform
- What problems should we pay attention to when building a programmatic trading system?
- [ADI low-power 2k code] Based on ADuCM4050, ADXL363, TMP75 acceleration, temperature detection and serial port printing, buzzer playing music (lone warrior)
- The impact of programmatic trading and subjective trading on the profit curve!
猜你喜欢
【C语言】入门
A simple JVM tuning, learn to write it on your resume
LeetCode刷题第12天二叉树系列之《104 二叉树的最大深度》
LeetCode刷题第17天之《3 无重复字符的最长子串》
机器学习怎么学?机器学习流程
Differences and connections between distributed and clustered
Is Redis old?Performance comparison between Redis and Dragonfly
【FPGA】day21- moving average filter
【FPGA】day22-SPI protocol loopback
leetCode刷题14天二叉树系列之《 110 平衡二叉树判断》
随机推荐
【组成原理 九 CPU】
【FPGA】day22-SPI protocol loopback
MYSQLg高级------聚簇索引和非聚簇索引
LeetCode Brush Questions Day 11 String Series "58 Last Word Length"
The FTP error code list
移动端地图开发选择哪家?
【C语言】入门
我的 archinstall 使用手册
机器学习中什么是集成学习?
Uni - app - access to Chinese characters, pinyin initials (according to the Chinese get pinyin initials)
When EasyCVR is connected to the GB28181 device, what is the reason that the device is connected normally but the video cannot be played?
LeetCode814算题第15天二叉树系列值《814 二叉树剪枝》
阿里云发布3大高性能计算解决方案
LeetCode刷题第10天字符串系列之《125回文串验证》
使用百度EasyDL实现施工人员安全装备检测
uni-app - city selection index list / city list sorted by A-Z (uview component library IndexList index list)
使用百度EasyDL实现森林火灾预警识别
【FPGA】设计思路——I2C协议
What should I do if the channel ServerID is incorrect when EasyCVR is connected to a Hikvision Dahua device and selects another cluster server?
使用jackson解析json数据详讲