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

输入输出样例

输入样例#1: 复制

5 3
Bessie
Jonathan
Montgomery
Alicia
Angola
se
nGo
Ont
输出样例#1: 复制

1
1
2
0
1

说明

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".

模拟

挨个字符枚举判断

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 1010
using namespace std;
char ch[N][N],s[N];
int n,m,k,l,len,ans[N];
int read()
{
    ,f=; char ch=getchar();
    ;ch=getchar();}
    +ch-',ch=getchar();
    return x*f;
}
int work(char *s)
{
    len=strlen(s);
    ;i<=n;i++)
    {
        k=;l=strlen(ch[i]);
        ;j<l;j++)
        {
            ||s[k]-ch[i][j]==) k++;
            if(k==len){ans[i]++;break;}
        }
    }
}
int main()
{
    n=read(),m=read();
    ;i<=n;i++)
     cin>>ch[i];
    ;i<=m;i++)
     cin>>s,work(s);
    ;i<=n;i++)
     printf("%d\n",ans[i]);
    ;
}

最新文章

  1. highcharts去掉版权|去掉水印链接(右下角)_
  2. refactor window_x64微信小程序环境搭建
  3. SQLServer 维护脚本分享(08)临时数据库(tempdb)
  4. QueryTask查询结果最多500条的问题
  5. Dom之标签属性
  6. 用ffmpeg把H264数据流解码成YUV420P
  7. JDBC中PreparedStatement和Statement的区别
  8. [转]Centos 6.5 优化 一些基础优化和安全设置
  9. 2017-12-19python全栈9期第四天第三节之iterable可迭代对象join之字符串和列表转换成字符串和range
  10. mantisbt的配置与安装
  11. leetcode1:两数之和
  12. ReCAPTCHA &amp; 手势验证
  13. 关于springboot
  14. kubernetes ui 搭建
  15. js 产生随机数
  16. 数据库like匹配的实现猜测
  17. Kubernetes 1.8火热出炉:稳定性、安全性与存储支持能力全面提升
  18. linux平台下防火墙iptables原理
  19. Java之集合(二十四)ConcurrentLinkedDeque
  20. CCF CSP 201609-3 炉石传说

热门文章

  1. ReaderWriterLockSlim 类
  2. 【Codeforces441E】Valera and Number [DP]
  3. 【BZOJ2946】公共串 [SAM]
  4. UIActivityIndicatorView---iOS-Apple苹果官方文档翻译
  5. OpenCVSSDpython目标探测对象检测
  6. HTML5获取地理位置信息并在Google Maps上显示
  7. 64_l3
  8. javascript反混淆之packed混淆
  9. Phoenix批量修改数据
  10. HUD-5379