1176. [郑州101中学] 月考

★★☆   输入文件:mtest.in   输出文件:mtest.out   简单对比
时间限制:1 s   内存限制:128 MB

【题目描述】

在上次的月考中Bugall同学违反了考场纪律还吃了处分,更可气的是在第二天的校会时
 间学校就此事做了全校通报. 现已知在当天校会时间有总共N个同学听到了有关Bugall的处分决定.
 
 Bugall同学在铁一有M个朋友,这M个人中有的可能听到了当天的处分决定,有的可能没
 有听到,现在Bugall同学想知道他有几个朋友听到了当天的处分通报.

【输入格式】

第一行为一个整数N,从第2行到N+1行,每行用一个长度不超过200的字符串表示
 一个人的名字.
  第N+2行为一个整数M,从第N+3行到N+M+2行,每行用一个长度不超过200的字符
 串表示Bugall同学一个朋友的名字.

【输出格式】

输出有几个Bugall同学的铁一朋友在当天的校会时间听到了Bugall处分通报.保证不重名。

【样例输入】

3
Dazui
Erge
Dapigu
2
Varpro
Erge

【样例输出】

1

#include<cstdio>
#include<cstring>
using namespace std;
struct Trie
{
Trie* son[];
bool f;
Trie()
{
for(int i=;i<;i++)
son[i]=NULL;
f=false;
}
}Root;
int main()
{
freopen("mtest.in","r",stdin);
freopen("mtest.out","w",stdout);
int n;
scanf("%d",&n);
//cout<<n<<endl;
while(n--)
{
char s[];scanf("%s",s);
int len=strlen(s);
Trie* p=&Root;
for(int i=;i<len;i++)
{
int x;
if(s[i]>='A'&&s[i]<='Z')
x=s[i]-'A';
else
x=s[i]-'a'; if(p->son[x]==NULL)
{
p->son[x]=new Trie; }
p=p->son[x];
}
p->f=true;
} int m;
scanf("%d",&m);
//cout<<m<<endl;
int ans=;
while(m--)
{
char s[];
scanf("%s",s);
int len=strlen(s);
Trie* p=&Root;
bool ff=true;
for(int i=;i<len;i++)
{
int x;
if(s[i]>='A'&&s[i]<='Z')
x=s[i]-'A';
else
x=s[i]-'a';
if(p->son[x]==NULL)
{
ff=false;
break;
}
p=p->son[x];
}
if(ff&&p->f)
ans++;
}
printf("%d\n",ans);
return ;
}

上面是一个异常神奇指针做法QAQ

cogs 1176. [郑州101中学] 月考 字典树的更多相关文章

  1. cogs 1176. [郑州101中学] 月考

    1176. [郑州101中学] 月考 ★   输入文件:mtest.in   输出文件:mtest.out   简单对比时间限制:1 s   内存限制:128 MB [题目描述] 在上次的月考中Bug ...

  2. cogs 1176. [郑州101中学] 月考 Set 做法

    1176. [郑州101中学] 月考 ★★☆   输入文件:mtest.in   输出文件:mtest.out   简单对比时间限制:1 s   内存限制:128 MB [题目描述] 在上次的月考中B ...

  3. cogs 1176. [郑州101中学] 月考 Map做法

    1176. [郑州101中学] 月考 ★★☆   输入文件:mtest.in   输出文件:mtest.out   简单对比时间限制:1 s   内存限制:128 MB [题目描述] 在上次的月考中B ...

  4. COGS——C1176. [郑州101中学] 月考

    http://cogs.pro/cogs/problem/problem.php?pid=1176 [题目描述] 在上次的月考中Bugall同学违反了考场纪律还吃了处分,更可气的是在第二天的校会时 间 ...

  5. oj2892(字典树)

    一改时间以后WA了,我就知道这题是考字典树,可惜代码怎么也不会敲了,郁闷. #include <stdio.h>#include <string.h>#include < ...

  6. 月考(cogs 1176)

    [题目描述] 在上次的月考中Bugall同学违反了考场纪律还吃了处分,更可气的是在第二天的校会时 间学校就此事做了全校通报. 现已知在当天校会时间有总共N个同学听到了有关Bugall的处分决定.  B ...

  7. S5第一次月考

    # Python五期月考一 # 1 介绍 # 满分100分,90分及格 # # 考试范围: # 1.Python语法 # 2.数据类型 # 3.流程控制 # 4.函数 # 5.模块 # # 考试时间: ...

  8. C#学习笔记(二十):C#总结和月考讲解

    m1w1d2_console_variable_constant 输入Console.WriteLine(); 输出Console.ReadLine(); 快捷键 折叠代码:快捷键“Ctrl+ K + ...

  9. 洛谷 P4256 公主の#19准备月考

    题目背景 公主在玩完游戏后,也要月考了.(就算是公主也要月考啊QWQ) 题目描述 公主的文综太差了,全校排名1100+(全校就1100多人),她分析了好久,发现她如果把所有时间放在选择题上,得分会比较 ...

随机推荐

  1. There is no PasswordEncoder mapped for the id "null"的解决办法

    今日在SpringBoot项目中使用 Spring Security ,登录时发现报500错,报错信息如下: There is no PasswordEncoder mapped for the id ...

  2. 安装 Sureface Hub 系统 Windows 10 team PPIPro 系统

    本文告诉大家如何安装这个系统 本文的方法我自己没试过,如果失败了,不要打我 下载地址 中文版 https://pan.baidu.com/s/1gAJSSE6KB9JHXo4BT_VfmA 其他请看 ...

  3. H3C配置路由器作为TFTP客户端

  4. linux虚拟机设置固定IP并实现联网,主机与虚拟机实现互ping

    ifconfig eth0 up 启用第一块网卡 onboot=yes 自动启动 service network restart 重启网络服务 使用虚拟机添加一块桥接网卡 cp eth0 eth1 复 ...

  5. H3C STP配置示例

  6. css元素居中的几种方式

    1.水平居中 <div style="width:200px;margin:0 auto;background-color: yellow;">水平居中</div ...

  7. 性能测试基础-HTTP用例设计

    JSON格式请求: web_custom_request("https://xx.xx.xx.xx:xx/pvcpappinf//msgcustomization/xinPowGenDay, ...

  8. TOJ5705动态序列操作(STL or treap)

    传送门:动态序列操作 在一个动态变化的序列中,完成以下基本操作: (1)插入一个整数 (2)删除一个整数 (3)查找序列中最大的数 (4)查找序列中最小的数 (5)求x的前驱(前驱定义为不大于x的序列 ...

  9. CodeForces - 375D Tree and Queries (莫队+dfs序+树状数组)

    You have a rooted tree consisting of n vertices. Each vertex of the tree has some color. We will ass ...

  10. 【31.93%】【codeforces 670E】Correct Bracket Sequence Editor

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...