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";
}
codeforces 868A Bark to Unlock的更多相关文章
- Codeforces 868A Bark to Unlock【字符串+二维string输入输出+特判】
A. Bark to Unlock time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #438 A. Bark to Unlock
题意:给你一个原串和n个子串,问你这n个子串任意组合起来能不能使原串出现,串的长度为2. Examples Input ya4ahoytoha Output YES Input hp2http Out ...
- 【Codeforces Round #438 A】Bark to Unlock
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 枚举它是在连接处,还是就是整个字符串就好. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc+ ...
- Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
A. Bark to Unlock 题目链接:http://codeforces.com/contest/868/problem/A 题目意思:密码是两个字符组成的,现在你有n个由两个字符组成的字符串 ...
- Codeforces Round #438 (Div.1+Div.2) 总结
本来兴致勃勃的想乘着这一次上紫,于是很早很早的到了机房 但是好像并没有什么用,反而rating-=47 Codeforces Round #438(Div.1+Div.2) 今天就这样匆匆的总结一下, ...
- 【Codeforces Round 438 A B C D 四个题】
题目所在比赛的地址在这里呀 A. Bark to Unlock ·述大意: 输入一个目标串.然后输入n(1<=n<=100)个串,询问是否可以通过这些串收尾相接或者它本身拼出目 ...
- Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combine
最近只想喊666,因为我是真得菜,大晚上到网吧打代码还是很不错的嘛 A. Bark to Unlock time limit per test 2 seconds memory limit per t ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem 2-SAT
题目链接:http://codeforces.com/contest/776/problem/D D. The Door Problem time limit per test 2 seconds m ...
- 打开程序总是会提示“Enter password to unlock your login keyring” ,如何成功关掉?
p { margin-bottom: 0.1in; line-height: 120% } 一.一开始我是按照网友所说的 : rm -f ~/.gnome2/keyrings/login.keyrin ...
随机推荐
- 新手使用mac上的textedit写HTML时遇到的问题及解决办法
刚开始在mac上学习HTML,总结一下遇到的问题和解决办法 问题:使用textedit编写html,在网页上却仍然显示的是代码. 解决办法: 打开textedit后打开文本编辑 选择偏好设置 按如图所 ...
- 听翁恺老师mooc笔记(12)--结构中的结构
结构数组: 和C语言中的int,double一样,一旦我们做出一个结构类型,就可以定义这个结构类型的变量,也可以定义这个结构类型的数组.比如下面这个例子: struct date dates[100] ...
- 2017-2018-1 Java演绎法 第一周 作业
团队学习:<构建之法> [团队成员]: 学号 姓名 负责工作 20162315 马军 日常统计,项目部分代码 20162316 刘诚昊 项目部分代码,代码质量测试 20162317 袁逸灏 ...
- 22.C++- 继承与组合,protected访问级别
在C++里,通过继承和组合实现了代码复用,使得开发效率提高,并且能够通过代码看到事物的关系 组合比继承简单,所以在写代码时先考虑能否组合,再来考虑继承. 组合的特点 将其它类的对象作为当前类的成员使用 ...
- 同样是IT培训,为什么人家月薪过万,你才几千,问题在哪?!
听过一句话"360行,行行转IT",虽然有些夸张,但也不难看出IT行业的火爆程度.从李总理提的"互联网+大数据"开始,中国的这场"互联网+" ...
- 24.C++- 抽象类(存虚函数)、接口、多重继承
抽象类和接口 什么是抽象类 用来表示现实世界中的抽象概念 是一种只能定义类型,而不能产生对象的类 只能被子类继承,且抽象类的相关成员函数没有完整的体现,用来被子类重写. 比如图形(Shape)类, 就 ...
- javascript学习(3)循环和判断
continue:: break:: 一.for循环 1.for(i=1;i<6;i++)循环 2.for(x in jsonObject)循环 二.while循环 1.while循环 2.do ...
- python入门(6)输入和输出
python入门(6)输入和输出 输出 >>> print 'hello, world' >>> print 'The quick brown fox', 'jum ...
- Spring Security入门(3-6)Spring Security 的鉴权 - 自定义权限前缀
- JavaScript利用数组原型,添加方法实现遍历多维数组每一个元素
原型就是提供给我们为了让我们扩展更多功能的. 今天学习了用js模拟底层代码,实现数组多维的遍历.思想是在数组原型上添加一个方法. // js中的数组forEach方法,传入回掉函数 能够帮助我们遍历数 ...