codeforces 868A Bark to Unlock
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个长为单词,是否有一段连续的单词串包含密码
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).
ya
4
ah
oy
to
ha
YES
hp
2
ht
tp
NO
ah
1
ha
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判断,还考虑自己就是密码的情况
#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";
}
最新文章
- 从express源码中探析其路由机制
- iOS Waxpatch项目(动态更新)
- PHP获取用户真实IP
- 解决WordPress后台安装主题、插件图片不显示的问题
- shellinabox安装
- 安装cgdb
- 2016年11月3日 星期四 --出埃及记 Exodus 19:19
- Jasper_dataSource_CSV data source config
- 香港多IP站群服务器-搭建多IP代理服务器、游戏加速服务器
- ubuntu系统搭建以太坊私有链
- C# 关键字--virtual(转)
- TCP的核心系列 — 重传队列的更新和时延的采样(一)
- 学习PYTHON之路, DAY 10 进程、线程、协程篇
- 表达式引擎aviator
- Window应急响应(二):蠕虫病毒
- noi题库(noi.openjudge.cn) 1.13编程基础之综合应用 T12 分数求和
- 从咖啡馆的经营看 Web 应用的扩展
- AnimationState
- ETL开发
- ThreadPoolExecutor 异常