G.易彰彪的一张表

易彰彪最近有点奇怪,一向爱打游戏他最近居然盯着一张全是大小写字母的表在看,好像在找什么东西。他说,这是他女神给他的一张表,他需要回答女神的问题——在忽略大小写(即大写字母和小写字母视为同一字母)的情况下,是否能在表中找到某一连续的字符串(第 ii 行的尾部和第 i + 1i+1 行的头部视为相连)。但是英语不好的易彰彪一看到字母就头晕,聪明的你能帮他解决这个问题吗?

输入格式:

输入有多组测试数据。

每组第一行会输入两个整数 nn 和 mm,分别是表的行数和列数,1 leq n, m leq 301n,m30。

第 22 行到第 n + 1n+1 行,每行输入一个长度为 mm的字符串,表示表的内容。

第 n + 2n+2 行输入易彰彪想要在表中找到的字符串。

输出格式:

如果按照题目描述能够在表中找到目标字符串,输出YES, 否则输出NO

样例1

输入:

5 5
yiZha
nGBia
oaerg
htyfj
awert
yizhangbiao

输出:

YES

字符串查找。

/* ***********************************************
Created Time  :2016/4/24 17:36:28
File Name     :1.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
    int x,y;
};
struct cmp{
    bool operator()(Node a,Node b){
        if(a.x==b.x) return a.y> b.y;
        return a.x>b.x;
    }
};

bool cmp(int a,int b){
    return a>b;
}
string t,s;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    //freopen("out.txt","w",stdout);
    int n,m;
    
    while(cin>>n>>m){
        s="";
        for(int i=1;i<=n;i++){
            cin>>t;
            for(int j=0;j<m;j++){
                if(t[j]<='Z'&&t[j]>='A')t[j]=char(t[j]+32);
            }
            s+=t;
        }
        string w;
        cin>>w;
        for(int i=0;i<w.size();i++){
            if(w[i]<='Z'&&w[i]>='A')w[i]=char(w[i]+32);
        }
        size_t x = s.find(w);
        if(x!=string::npos){
            puts("YES");
        }
        else puts("NO");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/pk28/p/5427587.html