A. Bark to Unlock

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.

Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark ndistinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not.

Input

The first line contains two lowercase English letters — the password on the phone.

The second line contains single integer n (1 ≤ n ≤ 100) — the number of words Kashtanka knows.

The next n lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct.

Output

Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise.

You can print each letter in arbitrary case (upper or lower).

Examples
input
ya
4
ah
oy
to
ha
output
YES

 
input
 
hp
2
ht
tp
output
NO

 
input
ah
1
ha
output
YES


In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES".

In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring.

In the third example the string "hahahaha" contains "ah" as a substring.

【题意】:给出一个目标串(长度为2),再给n行长度为2的文本串,要求在文本串(可连续多个相同,不要求有序)中判断是否有该目标串。

【分析】:要注意当文本串里面刚好含有目标串特判为YES,否则根据文本串的某个头=目标串的尾&&文本串的某个尾=目标串的头,枚举即可。

【代码】:

#include<bits/stdc++.h>
using namespace std;
string s;
string ss[];
int n;
int main()
{
cin>>s;
cin>>n;
for(int i=;i<=n;i++)
{
cin>>ss[i];
if(s==ss[i])
{
cout<<"YES"; //或者直接flag标记,在末尾统一判断后输出
return ; //注意不能用break 因为下面还有循环 会输出2个 YESNO这样
}
} for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if( s[]==ss[i][]&&s[]==ss[j][] ) {
cout<<"YES";
return ;
}
}
} cout<<"NO";
}

Codeforces 868A Bark to Unlock【字符串+二维string输入输出+特判】的更多相关文章

  1. codeforces 868A Bark to Unlock

    As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly ...

  2. Codeforces Round #524 (Div. 2)C 二维坐标系求俩矩形面积交

    题:https://codeforces.com/contest/1080/problem/C 题意:给n*m的二维坐标系,每个位置(xi,yi)都表示一个方格,(1,1)的位置是白色,整个坐标系黑白 ...

  3. codeforces 677D D. Vanya and Treasure(二维线段树)

    题目链接: D. Vanya and Treasure time limit per test 1.5 seconds memory limit per test 256 megabytes inpu ...

  4. Codeforces 846D Monitor(简单二分+二维BIT)

    D. Monitor time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  5. 牛客练习赛1 矩阵 字符串二维hash+二分

    题目 https://ac.nowcoder.com/acm/contest/2?&headNav=www#question 解析 我们对矩阵进行二维hash,所以每个子矩阵都有一个额hash ...

  6. Codeforces 713D Animals and Puzzle(二维ST表+二分答案)

    题目链接 Animals and Puzzle 题意  给出一个1e3 * 1e3的01矩阵,给出t个询问,每个询问形如x1,y1,x2,y2 你需要回答在以$(x1, y1)$为左上角,$(x1, ...

  7. Codeforces Round #369 (Div. 2) A. Bus to Udayland【字符串/二维字符数组求连起来的座位并改为其他字符】

    A. Bus to Udayland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. Codeforces 999F Cards and Joy(二维DP)

    题目链接:http://codeforces.com/problemset/problem/999/F 题目大意:有n个人,n*k张卡牌,每个人会发到k张卡牌,每个人都有一种喜欢的卡牌f[i],当一个 ...

  9. C语言-对字符串二维数组各个元素进行比较-十进制数转化为其他进制数-进行规则矩阵的输出-190225

    //编写一个函数:从传入的num个字符中找到最长的一个字符,并通过max传回该串地址. //重点:切记这里a[0]就是一个地址. #include<conio.h> #include< ...

随机推荐

  1. servletContex.getRealPath 获取的是拼接后的地址 是虚假的

    servletContex.getRealPath 获取的是拼接后的地址 是虚假的

  2. JDK的弃儿:Vector、Stack、Hashtable、Enumeration

    随着JDK的发展,一些设计缺陷或者性能不足的类库难免会被淘汰,最常见的就是Vector.Stack.HashTable和Enumeration了. Vector(@since 1.0) 首先看看Vec ...

  3. LeetCode -- Best Time to Buy and Sell Stock系列

    Question: Best Time to Buy and Sell Stock Say you have an array for which the ith element is the pri ...

  4. ACM 竞赛高校联盟 练习赛 第二场 B&C

    B. 题解: 枚举约数即可,判断n个数能否填约数的整数倍 #include <iostream> #include <cstring> #include <cstdio& ...

  5. Antlr 在 idea 中正确使用的方式

    问题 Caused by: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN ...

  6. JS格式化 /Date(xxxxxx)/的日期类型

    //用来转换/Date(xxxxxx)/类型的JSON日期为要求的日期格式字符串String.prototype._formatJsonDate = function (format) { var s ...

  7. 理解First Chance和Second Chance避免单步调试

    原文链接地址:http://blog.csdn.net/Donjuan/article/details/3859160 在现在C++.Java..Net代码大行其道的时候,很多代码错误(Bug)都是通 ...

  8. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B

    B. Problems for Round time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  9. php SPL四种常用的数据结构

    1.栈[先进后出] $stack = new SplStack(); $stack->push('data1'); $stack->push('data2'); $stack->pu ...

  10. Python爬虫学习笔记之爬今日头条的街拍图片

    代码: import requests import os from hashlib import md5 from urllib.parse import urlencode from multip ...