codeforces 868A Bark to Unlock
来源:互联网 发布:mac 结构图软件 编辑:程序博客网 时间:2024/06/05 14:41
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.
题目大意:给你一个目标字符串,再给你好几个字符串,问能不能用这些字符串组合成目标字符串
#include<bits/stdc++.h>using namespace std;int main(){ string beg; cin>>beg; int n; cin>>n; string str[n]; for(int i=0;i<n;i++) cin>>str[i]; for(int i=0;i<n;i++){ if(str[i]==beg){ cout<<"YES"<<endl; return 0; } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ string tmp=str[i]+str[j]; if(tmp[1]==beg[0]&tmp[2]==beg[1]){ cout<<"YES"<<endl; return 0; } } } cout<<"NO"<<endl; return 0;}
- codeforces 868A Bark to Unlock
- Codeforces 868A Bark to Unlock 水题
- CodeForces 868A Bark to Unlock
- codeforces 868A Bark to Unlock
- Codeforces 868 A Bark to Unlock(水题)
- Codeforces Round #438 A. Bark to Unlock
- Bark to Unlock CodeForces
- 【模拟】Codeforces Round #438 A. Bark to Unlock 题解
- CF 868 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
- Codeforces868A Bark to Unlock
- How to unlock computer
- How to solve SQL Server Error 1222 i.e Unlock a SQL Server table
- Two ways to unlock iphone4
- CodeForces 711A A. Bus to Udayland
- how to unlock /opt in ubuntu
- Enter password to unlock your login keyring
- ACM新人方向引导
- 大批量更新数据mysql批量更新的四种方法
- 雅可比(Jacobian)矩阵
- DeepLung论文笔记
- JDBC连接数据库
- codeforces 868A Bark to Unlock
- Python optparser库详解
- <设计模式可复用面向对象软件的基础> [1.4]、原型(C#)
- js中html,text,val 比较
- 51nod 1289 大鱼吃小鱼 【stack的使用】
- 三条命令解决Git 如何删除远程服务器文件同时保留本地文件
- 爬取环境信息实例
- 上传大文件失败问题记录
- SQLSTATE[HY000] [1130] Host '127.0.0.1' is not allowed to connect to this MySQL server怎么解决?