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 ...
随机推荐
- centos 6.5 hadoop 2.3 初配置
为了安装hadoop废了好大的劲才把esxi5.5给装好. 同时装了centos6.5,由于hadoop里面有个免密码登陆所以这里讲的就是免密码登陆. 看了大家的博客文章发现转发的一部分,写ubunt ...
- libeXosip2(1) -- Modules
Modules Here is a list of all modules: [detail level 12] The eXtented eXosip stack LibeXosip2 Versio ...
- Find the Celebrity 解答
Question Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there ma ...
- HDU4171--bfs+树
第一开始想成了DP.尼玛后来才发现只有N条边,那就简单了.. 从起点S遍历整棵树,从某点跳出来回到终点T,问最短路长度.然而从某点跳出时走过的路径是一个定值.... 长度为整棵树的边长和sum*2-d ...
- hdu 5432 Pyramid Split(二分搜索)
Problem Description Xiao Ming is a citizen who's good at playing,he has lot's of gold cones which ha ...
- .NET 面试题(1)
1.简述 private. protected. public. internal 修饰符的访问权限. private:私有成员,在类的内部才能访问 protected:保护成员,在该类内部和继承本类 ...
- Javascript 中的变量
var a; console.log("The value of a is " + a); // The value of a is undefined console.log(& ...
- java编程排错技巧
一.Eclipse提示错误The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from re ...
- 07_DICTIONARY_ACCESSIBILITY
07_DICTIONARY_ACCESSIBILITY 控制对系统权限的限制: TRUE 有相应系统权限,允许访问SYS下的对象. FALSE 确保拥有可以访问任何对象的系统权限,但不可以访问SYS下 ...
- ASP.NET导入Excel到SQL数据库
protected void btnChange_Click(object sender, EventArgs e) { UserInfoClass tClass = (UserInfoClass)S ...