bzoj1622 [Usaco2008 Open]Word Power 名字的能量
Description
Input
Output
Sample Input
Bessie
Jonathan
Montgomery
Alicia
Angola
se
nGo
Ont
INPUT DETAILS:
There are 5 cows, and their names are "Bessie", "Jonathan",
"Montgomery", "Alicia", and "Angola". The 3 good strings are "se",
"nGo", and "Ont".
Sample Output
1
2
0
1
OUTPUT DETAILS:
"Bessie" contains "se", "Jonathan" contains "Ont", "Montgomery" contains
both "nGo" and "Ont", Alicia contains none of the good strings, and
"Angola" contains "nGo".
坑爹的字符串处理啊……调了我好久
就是枚举每个名字可以和给定的m个字符串匹配几个,这里匹配指名字的某一个子序列等于给定的字符串
主要是读入的时候字符串长度纠结了好久……
然后扫的时候就是枚举名字和字符串,然后两个指针指着两个串当前匹配的位置,然后往后移就可以了
- #include<cstdio>
- struct cow{
- int len;
- char ch[1010];
- }c[1010];
- struct pipei{
- int len;
- char ch[101];
- }p[110];
- int n,m,s1,s2;
- int ans[1010];
- int main()
- {
- scanf("%d%d",&n,&m);
- for (int i=1;i<=n;i++)
- {
- scanf("%s",c[i].ch);
- while (c[i].ch[c[i].len])
- {
- if (c[i].ch[c[i].len]<'a')
- c[i].ch[c[i].len]=c[i].ch[c[i].len]+32;
- c[i].len++;
- }
- }
- for (int i=1;i<=m;i++)
- {
- scanf("%s",p[i].ch);
- while (p[i].ch[p[i].len])
- {
- if (p[i].ch[p[i].len]<'a')
- p[i].ch[p[i].len]=p[i].ch[p[i].len]+32;
- p[i].len++;
- }
- }
- for (int i=1;i<=n;i++)
- for (int j=1;j<=m;j++)
- {
- s1=0;s2=0;
- while (s1<c[i].len&&s2<p[j].len)
- {
- if (c[i].ch[s1]==p[j].ch[s2])s2++;
- s1++;
- }
- if (s2==p[j].len)ans[i]++;
- }
- for (int i=1;i<=n;i++)
- printf("%d\n",ans[i]);
- }
bzoj1622 [Usaco2008 Open]Word Power 名字的能量的更多相关文章
- BZOJ 1622: [Usaco2008 Open]Word Power 名字的能量
题目 1622: [Usaco2008 Open]Word Power 名字的能量 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 349 Solved ...
- 1622: [Usaco2008 Open]Word Power 名字的能量
1622: [Usaco2008 Open]Word Power 名字的能量 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 370 Solved: 18 ...
- [Usaco2008 Open]Word Power 名字的能量
1622: [Usaco2008 Open]Word Power 名字的能量 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 408 Solved: 19 ...
- 【BZOJ】1622: [Usaco2008 Open]Word Power 名字的能量(dp/-模拟)
http://www.lydsy.com/JudgeOnline/problem.php?id=1622 这题我搜的题解是dp,我也觉得是dp,但是好像比模拟慢啊!!!! 1400ms不科学! 设f[ ...
- BZOJ——1622: [Usaco2008 Open]Word Power 名字的能量
http://www.lydsy.com/JudgeOnline/problem.php?id=1622 Description 约翰想要计算他那N(1≤N≤1000)只奶牛的名字的能量.每只 ...
- bzoj 1622: [Usaco2008 Open]Word Power 名字的能量【模拟】
模拟即可,注意包含可以是不连续的 方便起见读入的时候全转成小写 #include<iostream> #include<cstdio> using namespace std; ...
- BZOJ_1622_[Usaco2008_Open]_Word_Power_名字的能量_(字符匹配_暴力)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1622 给出多个文本串和模式串,求每个文本串中有多少模式串. 分析 直接暴力... #inclu ...
- bzoj1622 / P2908 [USACO08OPEN]文字的力量Word Power
P2908 [USACO08OPEN]文字的力量Word Power 第一眼:AC自动机(大雾) 直接暴力枚举即可. 用<cctype>的函数较方便(还挺快) $isalpha(a)$:$ ...
- 洛谷——P2908 [USACO08OPEN]文字的力量Word Power
P2908 [USACO08OPEN]文字的力量Word Power 题目描述 Farmer John wants to evaluate the quality of the names of hi ...
随机推荐
- 【转】Android 4.0.3 CTS 测试
原文网址:http://blog.csdn.net/zxm317122667/article/details/8508013 Android-CTS 4.0.3测试基本配置 1. Download C ...
- libeXosip2(2) -- General purpose API.
General purpose API. general purpose API in libeXosip2-4.0.0. More... Modules eXosip2 configuration ...
- unix c 06
文件操作 fcntl-> 复制文件描述符/取文件状态/文件锁 文件一系列函数-> access/chmod/truncate/... 目录操作 相关函数:mkdir/rmdir/telld ...
- 第01讲- Android背景知识
第01讲Android背景知识 Android是基于Linux系统 Android系统框图 : 第一.操作系统层(OS) 第二.各种库(Libraries)和Android 运行环境(RunTime) ...
- 【Struts2】新建一个Struts2工程,初步体验MVC
实现目标 地址栏输入http://localhost:88/Struts2HelloWorld/helloworld.jsp 输入用户名,交由http://localhost:88/Struts2He ...
- BZOJ 2648/2716(SJY把件-KD_Tree)[Template:KD_Tree]
2648: SJY把件 Time Limit: 20 Sec Memory Limit: 128 MB Submit: 1180 Solved: 391 [id=2648" style= ...
- ios 自己定义导航栏和切割线
自己定义导航栏: // CustomNaviBarView.h #import <UIKit/UIKit.h> @interface CustomNaviBarView : UIView ...
- UIProgressView-初识IOS
好几天没更新了,学的时候太紧,没时间复习了都.今天刚好有时间,多更几个. 今天复习的是UIProgressView,我们常见使用在修改某些属性的时候经常用到,比如透明度,今天我们介绍一个简单的使用例子 ...
- NET基础课--NET的一些概念0
0.CIL--公共中间语言 VC++:经过预编译,编译,汇编和链接生成本地可执行代码,支持它运行的是OS和本地cpu指令集. C#: 在.net框架下类似c#的高级语言经过编译生成的文件叫程序集 ...
- Eclipse闪退解决办法
解决方式: 1.通过在命令行中输入“where java”,找到除jdk目录下的所有java相关程序,直接删掉(一般会在C:\WINDOWS\system32下) 2.内存不足,打开Eclipse目录 ...