POJ 2896 另解暴力
就是简单的用strstr函数对字符串进行处理。
另解:暴力(就是用strstr函数对字符串进行处理)另解:暴力(普通的字符串处理 。关键是strstr函数):
#include<stdio.h>
#include<string.h> struct Bing
{
char name[210];
int num;
}bing[510]; struct Web
{
char name[10010];
int num;
bool ok;
int a[4];
}web[1010]; int tot = 0; int main()
{
int n, m;
while(scanf("%d",&n) != EOF)
{
for (int i=0; i<1010; ++i)
{
memset(web[i].name, 0, sizeof(web[i].name));
web[i].ok = false;
memset(web[i].a, -1, sizeof(web[i].a));
web[i].num = 0;
}
tot = 0;
for (int i=0; i<n; ++i)
{
scanf("%s", bing[i].name);
bing[i].num = i+1;
}
scanf("%d", &m);
for (int i=0; i<m; ++i)
{
scanf("%s", web[i].name);
web[i].num = i + 1;
int cnt = 0;
for (int j=0; j<n; ++j)
{
if (strstr(web[i].name, bing[j].name))
{
web[i].ok = true;
web[i].a[cnt++] = j;
if (cnt == 3)
break;
}
}
} for (int i=0; i<m; ++i)
{
if (web[i].ok)
{
tot++;
printf("web %d:", web[i].num);
for (int j=0; j<3; ++j)
{
if (web[i].a[j] != -1)
{
printf(" %d", web[i].a[j] + 1);
}
}
printf("\n");
}
}
printf("total: %d\n", tot);
}
return 0;
}
POJ 2896 另解暴力的更多相关文章
- POJ 2896 AC自动机 or 暴力
DESCRIPTION :大意是说.给你n个代表病毒的字符串.m个表示网站的字符串.让你计算有多少个网站被病毒感染了.被那些病毒感染了. 刚开始就想暴力.然而,忽略了条件:每个网站最多有三个病毒.于是 ...
- poj 3714 Raid【(暴力+剪枝) || (分治法+剪枝)】
题目: http://poj.org/problem?id=3714 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27048#prob ...
- poj 2021 Relative Relatives(暴力)
题目链接:http://poj.org/problem?id=2021 思路分析:由于数据较小,采用O(N^2)的暴力算法,算出所有后代的年龄,再排序输出. 代码分析: #include <io ...
- POJ 3522 Slim Span 暴力枚举 + 并查集
http://poj.org/problem?id=3522 一开始做这个题的时候,以为复杂度最多是O(m)左右,然后一直不会.最后居然用了一个近似O(m^2)的62ms过了. 一开始想到排序,然后扫 ...
- poj 2585 Window Pains 暴力枚举排列
题意: 在4*4的格子中有9个窗体,窗体会覆盖它之下的窗体,问是否存在一个窗体放置的顺序使得最后的结果与输入同样. 分析: 在数据规模较小且不须要剪枝的情况下能够暴力(思路清晰代码简单),暴力一般分为 ...
- 【BZOJ-4059】Non-boring sequences 线段树 + 扫描线 (正解暴力)
4059: [Cerc2012]Non-boring sequences Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 440 Solved: 16 ...
- POJ 1012 Joseph 推导,暴力,约瑟夫环,打表 难度:2
http://poj.org/problem?id=1012 答案以954ms飘过,不过这道题可以轻松用打表过 思路:如果我们把每个人位于数组中的原始编号记为绝对编号,每次循环过后相对于绝对编号为0的 ...
- POJ - 3279(枚举+暴力)
Fliptile Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14297 Accepted: 5257 Descrip ...
- POJ 1840 Eqs 解方程式, 水题 难度:0
题目 http://poj.org/problem?id=1840 题意 给 与数组a[5],其中-50<=a[i]<=50,0<=i<5,求有多少组不同的x[5],使得a[0 ...
随机推荐
- 20145333茹翔 Exp7 网络欺诈技术防范
20145333茹翔 Exp7 网络欺诈技术防范 1.实验后回答问题 (1)通常在什么场景下容易受到DNS spoof攻击 局域网内的攻击,arp入侵攻击和DNS欺骗攻击 公共wifi点上的攻击. ( ...
- 20145334赵文豪《网络对抗》shellcode注入&Return-to-libc攻击深入
Shellcode注入 shellcode实际是一段代码,但却作为数据发送给受攻击服务器,将代码存储到对方的堆栈中,并将堆栈的返回地址利用缓冲区溢出,覆盖成为指向 shellcode 的地址 下载安装 ...
- 不是最强大的vimrc
一直都是使用vim作为我的主要编辑器,它大大提高了我的代码编辑效率.vim的配置高度灵活.插件丰富,恐怕100个人就有99种配置方法,网上关于vim配置的所谓“最强大的vimrc”之类的文章不少,博人 ...
- Python3基础 str lstrip 去掉字符串左边的空格
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- E: could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporary unavailable) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is an other process using it
1. 问题详细提示如下: E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarly unava ...
- 利用Ajax和Servlet实现输入框提示功能
目的和效果: 输入框输入字符串x,匹配后台传入的数据str,如果str中的元素包含字符串x,则提示. 后台代码: String x = request.ge ...
- UVa 820 因特网带宽(最大流)
https://vjudge.net/problem/UVA-820 题意: 给出所有计算机之间的路径和路径容量后求出两个给定结点之间的流通总容量. 思路: 裸的最大流问题.注意有个比较坑的地方,最后 ...
- MVC ---- Manager.ttinclude内容
http://www.infoq.com/cn/news/2009/11/T4-Multiple-Output 初次认识并尝试使用T4生成代码的时候,相关学习资料似乎比较少.不过现在VS2010 的M ...
- rostopic 命令
rostopic bw display bandwidth used by topic// rostopic delay display delay for topic which has heade ...
- c++ 对符合条件的元素进行计数(count_if)
#include <iostream> // cout #include <algorithm> // count_if #include <vector> // ...