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 ...
随机推荐
- Leetcode 14——Longest Common Prefix
题目:Write a function to find the longest common prefix string amongst an array of strings. 很简单的一个描述,最 ...
- Beta No.4
今天遇到的困难: 百度位置假死的问题研究发现并不是源于代码的问题,而是直接运行在主线程中会出现诸多问题 Fragment碎片刷新时总产生的固定位置的问题未果 今天完成的任务: 陈甘霖:修复了部分Bug ...
- 2017-2018-1 Java演绎法 小组成员贡献量汇总
[第一周]贡献量(31) [说明] 完成情况 是指 每次是否全部完成分配的任务,如果全部完成贡献量记为1,否则记为0,与贡献量(时间量)相加计算贡献比例,由于前十周有具体的任务分配,Alpha阶段(第 ...
- 2017 清北济南考前刷题Day 3 morning
实际得分:100+0+0=100 T1 右上角是必败态,然后推下去 发现同行全是必胜态或全是必败态,不同行必胜必败交叉 列同行 所以n,m 只要有一个是偶数,先手必胜 #include<cstd ...
- DELL EqualLogic PS存储硬盘故障数据恢复成功案例分享
DELL EqualLogic PS4000采用虚拟ISCSI SAN阵列,为远程或分支办公室.部门和中小企业存储部署带来企业级功能.智能化.自动化和可靠性.以简化的管理.快速的部署及合理的价格满足了 ...
- 点开GitHub之后,瑟瑟发抖...的我
我说句实在话啊,GitHub这个网址真的很能勾起人学习的欲望,一进入GitHub的注册页面真的让我这个英语学渣瑟瑟发抖,瞬间立下个flag:好好学习英语..... 我对python的求知欲怎么能被英语 ...
- python 模块部分补充知识
一.hashlib hashlib 模块主要用于加密相关的操作,代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法. 实例 ...
- Linux入门:vi 和 vim
vi编辑器是所有Unix及Linux系统下标准的编辑器,它的强大不逊色于任何最新的文本编辑器. 本文介绍了vi (vim)的基本使用方法,但对于普通用户来说基本上够了! 转自:http://www.l ...
- 【iOS】UIViewController基类的实现
继承是面向对象编程语言的三大特性之一,写好基类会给App的开发带来极大的方便.在iOS开发中,一般一个页面就对应一个ViewController,ViewController在开发中用的也很多,写一个 ...
- 在Android项目中使用Java8
前言 在过去的文章中我介绍过Java8的一些新特性,包括: Java8新特性第1章(Lambda表达式) Java8新特性第2章(接口默认方法) Java8新特性第3章(Stream API) 之前由 ...