题目链接:https://www.luogu.org/problemnew/show/P2580

我真的永远都爱stl

#include <map>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 100001;
map<string,int> a;
int n, m, num[maxn];
string s;
int main()
{
memset(num,-1,sizeof(num));
scanf("%d",&n);
for(int i = 1; i <= n; i++)
{
cin>>s;
a[s] = i;
num[a[s]]++;
}
scanf("%d",&m);
for(int i = 1; i <= m; i++)
{
cin>>s;
if(num[a[s]] ==-1)
{
printf("WRONG\n");
continue;//记得continue一下,要不然重复点错名的话会出错
}
num[a[s]]++;
if(num[a[s]] == 1)
{
printf("OK\n");
}
if(num[a[s]] > 1)
{
printf("REPEAT\n");
}
}
return 0;
}

后来我发现,trie也很棒棒哦qaq

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 500001;
char s[50];
int n, m, v[maxn], trie[maxn][26], opt, tot;
void insert()
{
int len = strlen(s);
int root = 0;
for(int i = 0; i < len; i++)
{
int id = s[i] - 'a';
if(!trie[root][id])
trie[root][id]=++tot;
root = trie[root][id];
}
v[root] = 1;
}
int find()
{
int len = strlen(s);
int root = 0;
for(int i = 0; s[i]; i++)
{
int now = s[i] - 'a';
if(trie[root][now] == 0) return false;
root = trie[root][now];
}
if(v[root] == 1)
{
v[root] = 2;
return 1;
}
else
return 2;
}
int main()
{
std::ios::sync_with_stdio(false);
cin>>n;
for(int i = 1; i <= n; i++)
{
cin>>s;
insert();
}
cin>>m;
for(int i = 1; i <= m; i++)
{
cin>>s;
opt = find();
if(opt == 0) printf("WRONG\n");
if(opt == 1) printf("OK\n");
if(opt == 2) printf("REPEAT\n");
}
}

【luogu P2580 于是他错误的点名开始了】 题解的更多相关文章

  1. luogu P2580 于是他错误的点名开始了

    luogu  P2580 于是他错误的点名开始了 https://www.luogu.org/problem/show?pid=2580 题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 他会一边 ...

  2. Luogu P2580 于是他错误的点名开始了 Trie树 字典树

    字典树裸题.每次插入询问串,查询的时候拿出来直接查,信息保留在节点上. #include <bits/stdc++.h> using namespace std; char s[51]; ...

  3. LUOGU P2580 于是他错误的点名开始了(trie树)

    传送门 解题思路 trie树模板

  4. 洛谷P2580 于是他错误的点名开始了 题解

    qwq!为什么!木有非结构体非指针的题解怎么阔以!所以, 我来辽~咻咻咻~ 题面 来分析, 我们可以先建一棵树,来存储整个名单, 然后再判断 ; i <= n; i++) { root = ; ...

  5. 洛谷 P2580 于是他错误的点名开始了 题解

    每日一题 day10 打卡 Analysis trie树模板题,只需用到简单的插入和查询就好了 如果想要学trie树,见信息学奥赛一本通·提高篇P82 #include<iostream> ...

  6. [Luogu 2580] 于是他错误的点名开始了

    [Luogu 2580] 于是他错误的点名开始了 不用好奇我为什么突然发水题题解- 突然觉得自己当年的幼儿园码风太幼稚,就试图把数据结构什么的用指针重写一遍- 想当年因为空间开太大而全 RE,调了一下 ...

  7. P2580 于是他错误的点名开始了(trie)

    P2580 于是他错误的点名开始了 题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 他会一边搓炉石一边点名以至于有一天他连续点到了某个同学两次,然后正好被路过的校长发现了然后就是一顿欧拉欧拉欧拉 ...

  8. 洛谷—— P2580 于是他错误的点名开始了

    https://www.luogu.org/problem/show?pid=2580 题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 他会一边搓炉石一边点名以至于有一天他连续点到了某个同学两次 ...

  9. P2580 于是他错误的点名开始了

    题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 他会一边搓炉石一边点名以至于有一天他连续点到了某个同学两次,然后正好被路过的校长发现了然后就是一顿欧拉欧拉欧拉(详情请见已结束比赛CON900). ...

随机推荐

  1. TOJ 2814 Light Bulb

    Description Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house ...

  2. Linux安装PHP加速器Xcache

    XCache 是一个又快又稳定的 PHP opcoolcode 缓存器. 经过良好的测试并在大流量/高负载的生产机器上稳定运行. 经过(在linux 上)测试并支持所有现行 PHP 分支的最新发布版本 ...

  3. Linux下Makefile的automake生成全攻略--转

    http://www.yesky.com/120/1865620.shtml 作为Linux下的程序开发人员,大家一定都遇到过Makefile,用make命令来编译自己写的程序确实是很方便.一般情况下 ...

  4. js 获取 Url.Action 设置area

    var url = '@Url.Action("UserEdit","User",new { Area = "Setup", id = 1} ...

  5. [转]Implementing User Authentication in ASP.NET MVC 6

    本文转自:http://www.dotnetcurry.com/aspnet-mvc/1229/user-authentication-aspnet-mvc-6-identity In this ar ...

  6. Spring JdbcTemplate 使用总结

    1.查询Object public Classify queryClassifById(int id){ String sql="select * from t_classify where ...

  7. 【学习笔记】实用类String的基本应用即常用方法

    一.String类概述 在Java中,字符串被作为String类型的对象来处理. String类位于java.lang包中,默认情况下会自动导入到所有的程序中. 创建String对象的方法如下: St ...

  8. 简单Java程序向实用程序的过度:二进制文件的读写

    File I/O中常见的文件读写: 1.字节流读写文本文件 FileInputStream; FileOutputStream; 2.字符流读写文本文件 FileReader; FileWriter; ...

  9. swagger快速开发

    转载:https://blog.csdn.net/xxoo00xx00/article/details/77163399 swagger 学习笔记 搭建环境: 1,jdk1.8 2,idea 3,sp ...

  10. Portals

    Portals Portals 提供了一种很好的将子节点渲染到父组件以外的 DOM 节点的方式. const appRoot = document.getElementById('app-root') ...