zoukankan      html  css  js  c++  java
  • A. Bark to Unlock

    A. Bark to Unlock
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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.

    Input

    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.

    Output

    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).

    Examples
    Input
    ya
    4
    ah
    oy
    to
    ha
    Output
    YES
    Input
    hp
    2
    ht
    tp
    Output
    NO
    Input
    ah
    1
    ha
    Output
    YES
    Note

    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.

    这题直接暴力枚举就够了。

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 char a[3];
     4 string k[105];
     5 int n;
     6 int main(){
     7   cin>>a;
     8   cin>>n;
     9   bool prime=true,flag=true;
    10   int t=0;
    11   while(t!=n){
    12       cin>>k[t];
    13       t++;
    14   }
    15   for(int i=0;i<n;i++){
    16     if(k[i]==a)
    17       {
    18         cout<<"YES"<<endl;
    19         return 0;
    20       }
    21   }
    22   for(int i=0;i<n;i++){
    23     if(k[i][1]==a[0]){
    24       prime=false;
    25     }
    26     if(k[i][0]==a[1]){
    27       flag=false;
    28     }
    29 
    30   }
    31 
    32   if(!flag&&!prime){
    33     cout<<"YES"<<endl;
    34   }else{
    35     cout<<"NO"<<endl;
    36   }
    37   return 0;
    38 }

  • 相关阅读:
    Reading papers_2(与GMM相关,ing...)
    Matlab DIP(瓦)ch11表示与描述练习
    HMM学习笔记_1(从一个实例中学习DTW算法)
    Matlab DIP(瓦)ch10图像分割练习
    前景检测算法_2(帧差法1)
    目标跟踪学习笔记_3(particle filter初探2)
    基础学习笔记之opencv(2):haartraining前将统一图片尺寸方法
    Reading papers_5(与human activity analysis综述相关,ing...)
    总结系列_4(C++知识学习,续...)
    HMM学习笔记_2(从一个实例中学习HMM前向算法)
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/7646001.html
Copyright © 2011-2022 走看看