洛谷P2908 [USACO08OPEN]文字的力量Word Power
题目描述
Farmer John wants to evaluate the quality of the names of his N (1 <= N <= 1000) cows. Each name is a string with no more than 1000 characters, all of which are non-blank.
He has created a set of M (1 <= M <= 100) 'good' strings (no
longer than 30 characters and fully non-blank). If the sequence letters of a cow's name contains the letters of a 'good' string in the correct order as a subsequence (i.e., not necessarily all next to each other), the cow's name gets 1 quality point.
All strings is case-insensitive, i.e., capital letters and lower case letters are considered equivalent. For example, the name 'Bessie' contains the letters of 'Be', 'sI', 'EE', and 'Es' in the correct order, but not 'is' or 'eB'. Help Farmer John determine the number of quality points in each of his cow's names.
约翰想要计算他那N(l < =N <= 1000)只奶牛的名字的能量.每只奶牛的名字由不超过1000个字 符构成,没有一个名字是空字体串.
约翰有一张“能量字符串表”,上面有M(1 < =M < =100)个代表能量的字符串.每个字符串 由不超过30个字体构成,同样不存在空字符串.一个奶牛的名字蕴含多少个能量字符串,这个名 字就有多少能量.所谓“蕴含”,是指某个能量字符串的所有字符都在名字串中按顺序出现(不 一定一个紧接着一个).
所有的大写字母和小写字母都是等价的.比如,在贝茜的名字“Bessie”里,蕴含有“Be” “si” “EE”以及“Es”等等字符串,但不蕴含“Ls”或“eB” .请帮约翰计算他的奶牛的名字 的能量.
输入输出格式
输入格式:
* Line 1: Two space-separated integers: N and M
* Lines 2..N+1: Line i+1 contains a string that is the name of the ith cow
* Lines N+2..N+M+1: Line N+i+1 contains the ith good string
输出格式:
* Lines 1..N+1: Line i+1 contains the number of quality points of the ith name
输入输出样例
说明
There are 5 cows, and their names are "Bessie", "Jonathan", "Montgomery", "Alicia", and "Angola". The 3 good strings are "se", "nGo", and "Ont".
"Bessie" contains "se", "Jonathan" contains "Ont", "Montgomery" contains both "nGo" and "Ont", Alicia contains none of the good strings, and "Angola" contains "nGo".
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
一开始我的想法是四重循环,第1层枚举牛的名字,第2层枚举牛的名字中的每个字符,第3层枚举能量字符串,第4层枚举能量字符串中的每个字符,后来发现这个想法不对,正确的思路是最外层枚举牛的名字,第2层枚举能量字符串,最里层枚举能量字符串中的每个字符。如果枚举的能量字符串里的字符在牛的名字里出现了,那么枚举下一个字符,当整个字符串全部枚举完成时,代表这个奶牛的名字“蕴含”这个能量字符串,能量+1,循环完后输出总能量就行了。
#include<iostream>
using namespace std;
int n,m,s;
string a[],b[];
int main()
{
cin>>n>>m;
for(int i=;i<=n;i++)
{
cin>>a[i];
for(int j=;j<a[i].length();j++)
if(a[i][j]>='A'&&a[i][j]<='Z')
a[i][j]+=;
}
for(int i=;i<=m;i++)
{
cin>>b[i];
for(int j=;j<b[i].length();j++)
if(b[i][j]>='A'&&b[i][j]<='Z')
b[i][j]+=;
}
for(int i=;i<=n;i++)
{
s=;
for(int j=;j<=m;j++)
{
int l=;
for(int k=;k<a[i].length();k++)
{
if(a[i][k]==b[j][l])
l++;
if(l==b[j].length())
{
s++;
break;
}
}
}
cout<<s<<endl;
}
return ;
}
代码
洛谷P2908 [USACO08OPEN]文字的力量Word Power的更多相关文章
- 洛谷——P2908 [USACO08OPEN]文字的力量Word Power
P2908 [USACO08OPEN]文字的力量Word Power 题目描述 Farmer John wants to evaluate the quality of the names of hi ...
- 洛谷 P2908 [USACO08OPEN]文字的力量Word Power
P2908 [USACO08OPEN]文字的力量Word Power 题目描述 Farmer John wants to evaluate the quality of the names of hi ...
- bzoj1622 / P2908 [USACO08OPEN]文字的力量Word Power
P2908 [USACO08OPEN]文字的力量Word Power 第一眼:AC自动机(大雾) 直接暴力枚举即可. 用<cctype>的函数较方便(还挺快) $isalpha(a)$:$ ...
- 洛谷P2905 [USACO08OPEN]农场危机Crisis on the Farm
P2905 [USACO08OPEN]农场危机Crisis on the Farm 题目描述 约翰和他的奶牛组建了一只乐队“后街奶牛”,现在他们正在牧场里排练.奶牛们分成一堆 一堆,共1000)堆.每 ...
- 洛谷——P2910 [USACO08OPEN]寻宝之路Clear And Present Danger
P2910 [USACO08OPEN]寻宝之路Clear And Present Danger 题目描述 Farmer John is on a boat seeking fabled treasur ...
- 洛谷 P2906 [USACO08OPEN]牛的街区Cow Neighborhoods | Set+并查集
题目: https://www.luogu.org/problemnew/show/P2906 题解: 垃圾水题 #include<cstdio> #include<algorith ...
- 洛谷 P2909 [USACO08OPEN]牛的车Cow Cars
传送门 题目大意: m个车道. 如果第i头牛前面有k头牛,那么这头牛的最大速度会 变为原本的速度-k*D,如果速度小于l这头牛就不能行驶. 题解:贪心 让初始速度小的牛在前面 代码: #include ...
- 洛谷P1435 回文字串(dp)
题意 题目链接 回文词是一种对称的字符串.任意给定一个字符串,通过插入若干字符,都可以变成回文词.此题的任务是,求出将给定字符串变成回文词所需要插入的最少字符数. 比如 “Ab3bd”插入2个字符后可 ...
- 洛谷 P2905 [USACO08OPEN]农场危机Crisis on the Farm
题目描述 约翰和他的奶牛组建了一只乐队“后街奶牛”,现在他们正在牧场里排练.奶牛们分成一堆 一堆,共1000)堆.每一堆里,30只奶牛一只踩在另一只的背上,叠成一座牛塔.牧场 里还有M(1 < ...
随机推荐
- Unity 行为树-基础
.前言 Unity里面的行为树又名BehaviorTree,最常用在NPC的敌人逻辑中. 二.基础说明(转载) 1.行为树的调用时间为每帧: 2.每个节点的状态只能下面3个中的其一:成功Success ...
- Table AUD$
How to Truncate, Delete, or Purge Rows from the Audit Trail Table AUD$ 转到底部 PURPOSE This document e ...
- scau 8616 汽车拉力比赛
上次我们过了二分图的最佳匹配,现在我们看一道题目,经典的二分图的最佳匹配题目 8616 汽车拉力比赛 时间限制:500MS 内存限制:1000K提交次数:71 通过次数:24 题型: 编 ...
- 安全性测试入门 (五):Insecure CAPTCHA 验证码绕过
本篇继续对于安全性测试话题,结合DVWA进行研习. Insecure Captcha不安全验证码 1. 验证码到底是怎么一回事 这个Captcha狭义而言就是谷歌提供的一种用户验证服务,全称为:Com ...
- c/c++ socket发送http请求访问网站
这几天课比较少,校园网上网要认证才能上网,每次必须输入学号密码,为了方便,写了一个自动登录以及如果在线,登录自服务系统强制下线的小工具. 强制下线思路:获取sessionID----------> ...
- RabbitMQ使用教程(三)如何保证消息99.99%被发送成功?
1. 前情回顾 RabbitMQ使用教程(一)RabbitMQ环境安装配置及Hello World示例 RabbitMQ使用教程(二)RabbitMQ用户管理,角色管理及权限设置 在以上两篇博客发布后 ...
- SOA框架
SOA是什么 估计很多人都听说过SOA这个词了,但是很多人还是不知道到底什么是SOA.开发人员很容易理解为是一个Web Service,但是这绝对不是SOA,那顶多只能算是SOA的一种实现方法.那么, ...
- android 开发-数据存储之文件存储
android的文件存储是通过android的文件系统对数据进行临时的保存操作,并不是持久化数据,例如网络上下载某些图片.音频.视频文件等.如缓存文件将会在清理应用缓存的时候被清除,或者是应用卸载的时 ...
- easyUI 鼠标悬停某行提示
最近参与公司的电子档案系统的开发,需求是需要用户鼠标悬停某一行时,需要根据后台业务数据进行提示. 档案系统开发采用的框架是struts2+mybatis+spring+easyUI开发,而前端的e ...
- mybatis使用说明
起步:1.创建一个maven项目工程.2.打开pom.xml配置文件,3.设置源代码编码方式为UTF-8.4.设置编译源代码的JDK版本.最好大于1.6版本.5. 重点--添加Mybatis的相关依赖 ...