Word Power S

题目描述

约翰想要计算他那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

样例输入

复制代码
5 3 
Bessie 
Jonathan 
Montgomery 
Alicia 
Angola 
se 
nGo 
Ont 

样例输出

复制代码
1 
1 
2 
0 
1 

参考代码

cpp 复制代码
#include <bits/stdc++.h>
#include <cstdio>
#define ll long long
using namespace std;

string s[1005];
string gs[105];
int ans[1005] = {0};

string lower(string s)
{
	string str = "";
	for(int i = 0; i < s.length(); i++)
	{
		if(s[i] >= 'A' && s[i] <= 'Z')
			str += s[i] + 32;
		else
			str += s[i];
	}
	
	return str;
}

int main()
{
	int n, m, v = 0;
	cin>>n>>m;
	
	for(int i = 1; i <= n; i++)
	{
		cin>>s[i];
		s[i] = lower(s[i]);
	}
	
	for(int i = 1; i <= m; i++)
	{
		cin>>gs[i];
		gs[i] = lower(gs[i]);
	}
	
	for(int i = 1; i <= n; i++)
	{
		bool flag = false;
		
		for(int t = 1; t <= m; t++)
		{
			int sh = -1;
			for(int j = 0; j < gs[t].length(); j++)
			{
				int kk = s[i].find(gs[t][j], sh+1); 
				if(kk <= sh)
				{
					flag = true;
					break;
				}
				sh = kk;
			}
			
			if(!flag)
			{
				ans[i]++;
			}
			flag = false;
		}
	}
	
	for(int i = 1; i <= n; i++)
	{
		cout<<ans[i]<<endl;
	}
	
	return 0;
}
相关推荐
C++ 老炮儿的技术栈1 小时前
基于Qt实现轻量化本地音乐播放器
开发语言·c++·qt·c·播放器·音乐
leisoo80971 小时前
财报数据怎么排雷本地化Python构建财务异常预警系统
人工智能·python·算法
qz_Serene3 小时前
C++:类和对象(上)
开发语言·c++
luj_17684 小时前
塔防牌:策略与卡牌的智慧碰撞
服务器·c语言·开发语言·经验分享·算法
郝学胜-神的一滴4 小时前
干货版《算法导论》17:二叉树核心原理、遍历逻辑与高阶实操全解
数据结构·c++·python·算法·计算机·编程
爱编程的小新☆4 小时前
【LeetCode】从递归到 Flood Fill:5 道题吃透 DFS 的选择、回溯与标记
java·算法·leetcode·深度优先·回溯·flood fill
Water_Sunzhipeng5 小时前
2024牛客暑期多校训练营1
算法
hetao17338375 小时前
2026-08-09~08-14 hetao1733837 的刷题记录
c++·算法
技术小黑5 小时前
RNN算法实战系列06 | LSTM 实现糖尿病探索与预测
rnn·算法·lstm
疯狂打码的少年5 小时前
【数据结构】二叉树的性质(五大性质+计算)
数据结构·笔记·算法