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 ...
随机推荐
- bzoj1060 [ZJOI2007]时态同步
Description 小Q在电子工艺实习课上学习焊接电路板.一块电路板由若干个元件组成,我们不妨称之为节点,并将其用数字1,2,3….进行标号.电路板的各个节点由若干不相交的导线相连接,且对于电路板 ...
- RFC3261--sip
本文转载自 http://www.ietf.org/rfc/rfc3261.txt 中文翻译可参考 http://wenku.baidu.com/view/3e59517b1711cc7931b716 ...
- <转载>构造函数与拷贝构造函数
原文地址http://www.cnblogs.com/waynelu/archive/2012/07/01/2572264.html 构造函数 构造函数.析构函数与赋值函数是每个类最基本的函数. 对于 ...
- python标准库 difflib-比较序列
# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #difflib比较序列 #版本2.1及之后 #作用:包含一些用来计 ...
- java的Future使用方法
首先,Future是一个接口,该接口用来返回异步的结果. package com.itbuluoge.mythread; import java.util.ArrayList; import java ...
- [CSS3] CSS Display Property: Block, Inline-Block, and Inline
Understanding the most common CSS display types of block, inline-block, and inline will allow you to ...
- js转换ascii编码如中文友转换为编码友;可防止乱码
- 黑马程序员 ——Java SE(1)
----<a href="http://www.itheima.com" target="blank">Java培训.Android培训.iOS培训 ...
- ASP.NET 后台下载文件方法
void DownLoadFile(string fileName) { string filePath = Server.MapPath(fileName);//路径 //以字符流的形式下载文件 F ...
- 高逼格的实现WiFi共享,不安装第三方wifi共享软件,两种方式实现开启wifi的功能
作为一枚程序员,不会点高逼格的doc命令,那么都有点感觉对不起自己的行业了,好了废话就到这里了 第一种方式: 首先使用cmd命令:window键+R 然后输入cmd回车 第一种方式: 第一步: 设 ...