Codeforces Round #438 A. Bark to Unlock
来源:互联网 发布:阿里云国际站 编辑:程序博客网 时间:2024/06/07 06:30
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.
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.
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).
ya4ahoytoha
YES
hp2http
NO
ah1ha
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.
找一下头尾是否是所要找的两个字符,并注意判断本体,如 ha 1 ha
#include <iostream>#include <cstdio>using namespace std;int main() { string s,ss; cin>>ss; int n; cin>>n; bool ms=false,me=false; while (n--) { cin>>s; if(s[0]==ss[ss.length()-1]) me=true; if (s[s.length()-1]==ss[0]) ms=true; if(s==ss) { me=true; ms=true; } } if (me&&ms) { cout<<"YES"<<endl; } else cout<<"NO"<<endl; // insert code here... //std::cout << "Hello, World!\n"; 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 #265 (Div. 1) A No to Palindromes!
- Codeforces Round #357 (Div. 2) E. Runaway to a Shadow
- Codeforces Round #369 (Div. 2) A. Bus to Udayland
- Codeforces Round #369 (Div. 2) A. Bus to Udayland
- Codeforces Round #369 (Div. 2) A. Bus to Udayland
- Codeforces Round #369 (Div. 2) A. Bus to Udayland【模拟】
- 【深入PHP 面向对象】读书笔记(十二)
- QListWidget和QTableWidget的使用和属性,QTableWidget和QListWidget样式表的设置,滚动条的样式设置
- kk《必然》后感之'使用'
- AngularJs实现简易的计算器
- first day
- Codeforces Round #438 A. Bark to Unlock
- 数据库 SQL实战练习
- OpenCV 2.4.9 配置使用
- python爬虫
- 引水入城
- JZOJ1239 邦德(加强版)
- 唉 再瞎搞你就一事无成了
- java基础-多态-接口
- Java并发编程:深入剖析ThreadLocal