北京林业大学校赛-G题(易彰彪的一张表)

题目链接点击打开链接


字串匹配问题!!我直接用的string中的find函数,,AC!最好还是用KMP算法防止超时!!

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <cmath>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int maxn = 55555;
int n, m;
int next1[maxn];
string s[33], t;
int main(void)
{
	//freopen("in.txt", "r", stdin);

	int i, j;
	while (scanf("%d%d", &n, &m) != EOF)
	{
		for (i = 0; i < n; i++)
		{
			cin >> s[i];
		}
		string ss = "";
		for (i = 0; i < n; i++)
		{
			ss += s[i];
		}
		for (i = 0; i < ss.length(); i++)
		{
			if (isupper(ss[i]))
				ss[i] = ss[i] - 'A' + 'a';
		}
		cin >> t;
		for (i = 0; i < t.length(); i++)
			if (isupper(t[i]))
				t[i] = t[i] - 'A' + 'a';
		if (ss.find(t) != string::npos)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}


你可能感兴趣的:(北京林业大学校赛)