暴力遍历-BZOJ-1622- [Usaco2008 Open]Word Power 名字的能量

Description
约翰想要计算他那N(1≤N≤1000)只奶牛的名字的能量.每只奶牛的名字由不超过1000个字待构成,没有一个名字是空字体串, 约翰有一张“能量字符串表”,上面有M(1≤M≤100)个代表能量的字符串.每个字符串由不超过30个字体构成,同样不存在空字符串.一个奶牛的名字蕴含多少个能量字符串,这个名字就有多少能量.所谓“蕴含”,是指某个能量字符串的所有字符都在名字串中按顺序出现(不一定一个紧接着一个).
所有的大写字母和小写字母都是等价的.比如,在贝茜的名字“Bessie”里,蕴含有“Be”
“sI”“EE”以及“Es”等等字符串,但不蕴含“lS”或“eB”.请帮约翰计算他的奶牛的名字的能量.
Input
第1行输入两个整数N和M,之后N行每行输入一个奶牛的名字,之后M行每行输入一个能量字符串.
Output

一共N行,每行一个整数,依次表示一个名字的能量.

Sample Input
5 3

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

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


题解:
直接先全处理为大写,然后暴力遍历地验证是否存在满足条件的子序列就行了。。。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int n,m;
const int fix='A'-'a';
char name[1005][1005],str[105][35];
int main()
{
    cin >> n >> m;
    for(int i=0;i<n;i++)
        cin >> name[i];
    for(int j=0;j<m;j++)
        cin >> str[j];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<strlen(name[i]);j++)
            if(name[i][j]>'Z')
                name[i][j]+=fix;
    }
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<strlen(str[i]);j++)
            if(str[i][j]>'Z')
                str[i][j]+=fix;
    }
    for(int i=0;i<n;i++)
    {
        int out=0,l=strlen(name[i]);
        for(int j=0;j<m;j++)
        {
            int now=0,left=strlen(str[j]);
            for(int z=0;z<strlen(str[j]);z++)
            {
                while(now<l && name[i][now]!=str[j][z])
                    now++;
                if(name[i][now]==str[j][z])
                {
                    left--;
                    now++;
                }
            }
            if(left==0)
                out++;
        }
        cout << out << endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值