【模拟】Codeforces Round #438 A. Bark to Unlock 题解
来源:互联网 发布:mac配置jenkins 编辑:程序博客网 时间:2024/05/17 12:25
A. Bark to Unlock
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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 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.
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.
按照题意匹配就完了
#include<iostream>#include<cstring>#include<cstdio>using namespace std;int n,tot;char yuan[5],tmp[10000000],xin[200][3];int main(){ scanf("%s%d",yuan,&n); for(register int i = 1; i <= n; i++) scanf("%s",xin[i]); for(register int i = 1; i <= n; i++) for(register int j = 1; j <= n; j++) tmp[tot++] = xin[i][0], tmp[tot++] = xin[i][1], tmp[tot++] = xin[j][0], tmp[tot++] = xin[j][1]; for(register int i = 1; i <= tot; i++) if(tmp[i-1] == yuan[0] && tmp[i] == yuan[1]) { printf("YES"); return 0; } printf("NO"); return 0;}
- 【模拟】Codeforces Round #438 A. Bark to Unlock 题解
- Codeforces Round #438 A. Bark to Unlock
- Codeforces Round #438 (Div. 1 + Div. 2 combined) A. Bark to Unlock(模拟)
- Codeforces Round #438 (Div. 1 + Div. 2 combined) A. Bark to Unlock
- codeforces 868A Bark to Unlock
- Codeforces 868A Bark to Unlock 水题
- CodeForces 868A Bark to Unlock
- codeforces 868A Bark to Unlock
- Bark to Unlock CodeForces
- Codeforces 868 A Bark to Unlock(水题)
- Codeforces868A Bark to Unlock
- CF 868 A. Bark to Unlock 【简单匹配】
- Codeforces Round #369 (Div. 2) A. Bus to Udayland【模拟】
- Codeforces Round #438 题解
- Codeforces Round #438 题解
- Educational Codeforces Round 25A-G题解
- Codeforces Round #440 (A-C ) 题解
- 【Codeforces 808A】【模拟】Lucky Year 题解
- Tensorflow实现经典损失函数
- spring和springmvc的关系
- [HDU 1502][动态规划]Regular Words
- RN新建项目ios执行analyzer issues
- andengine 精灵的水平翻转和上下翻转
- 【模拟】Codeforces Round #438 A. Bark to Unlock 题解
- 第三与第四次作业
- 学习笔记-图像识别(Photo OCR)
- 泛型总结
- 高效工作、学习方法初探
- SuperMap iDesktop中OracleSpatial数据源新建与打开失败小结
- 重写equals()和hashCode()方法,用于比较对象的内容
- json数据的序列化和反序列化
- Kvm 简介 安装 使用 桥接网络