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 n distinct 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.

题目大意:

密码是长为2的单词,有n个长为单词,是否有一段连续的单词串包含密码

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
Note

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判断,还考虑自己就是密码的情况

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
char s[],words[][];
int n,flag;
int main()
{int i,j;
cin>>s;
cin>>n;
for (i=;i<=n;i++)
{
cin>>words[i];
}
flag=;
for (i=;i<=n;i++)
{
int p=strcmp(words[i],s);
if (p==)
{
flag=;
break;
}
for (j=;j<=n;j++)
{
if (words[i][]==s[]&&words[j][]==s[])
{
flag=;
break;
}
}
}
if (flag)
cout<<"YES\n";
else cout<<"NO\n";
}

最新文章

  1. 从express源码中探析其路由机制
  2. iOS Waxpatch项目(动态更新)
  3. PHP获取用户真实IP
  4. 解决WordPress后台安装主题、插件图片不显示的问题
  5. shellinabox安装
  6. 安装cgdb
  7. 2016年11月3日 星期四 --出埃及记 Exodus 19:19
  8. Jasper_dataSource_CSV data source config
  9. 香港多IP站群服务器-搭建多IP代理服务器、游戏加速服务器
  10. ubuntu系统搭建以太坊私有链
  11. C# 关键字--virtual(转)
  12. TCP的核心系列 — 重传队列的更新和时延的采样(一)
  13. 学习PYTHON之路, DAY 10 进程、线程、协程篇
  14. 表达式引擎aviator
  15. Window应急响应(二):蠕虫病毒
  16. noi题库(noi.openjudge.cn) 1.13编程基础之综合应用 T12 分数求和
  17. 从咖啡馆的经营看 Web 应用的扩展
  18. AnimationState
  19. ETL开发
  20. ThreadPoolExecutor 异常

热门文章

  1. 使用jmeter+ant进行接口自动化测试(数据驱动)之二:利用apache-ant执行测试用例并生成HTML格式测试报告
  2. beta冲刺3
  3. highcharts 具体参数详解
  4. day-5 python协程与I/O编程深入浅出
  5. nyoj 对决吃桃
  6. MSIL实用指南-生成接口
  7. LeetCode &amp; Q169-Majority Element-Easy
  8. ssl双向认证
  9. kubernetes入门(01)kubernetes是什么?
  10. GIT入门笔记(5)- 创建版本库