Studying Alphabet Solution in JAVA

Problem

Not everyone probably knows that Chef has younger brother Jeff. Currently Jeff learns to read.

He knows some subset of the letter of Latin alphabet. In order to help Jeff to study, Chef gave him a book with the text consisting of N words. Jeff can read a word iff it consists only of the letters he knows.

Now Chef is curious about which words his brother will be able to read, and which are not. Please help him!

Input

The first line of the input contains a lowercase Latin letter string S, consisting of the letters Jeff can read. Every letter will appear in S no more than once.

The second line of the input contains an integer N denoting the number of words in the book.

Each of the following N lines contains a single lowecase Latin letter string Wi, denoting the ith word in the book.

Output

For each of the words, output "Yes" (without quotes) in case Jeff can read it, and "No" (without quotes) otherwise.

Constraints

  • 1 ≤ |S| ≤ 26
  • 1 ≤ N ≤ 1000
  • 1 ≤ |Wi| ≤ 12
  • Each letter will appear in S no more than once.
  • S, Wi consist only of lowercase Latin letters.

Subtasks

  • Subtask #1 (31 point)|S| = 1, i.e. Jeff knows only one letter.
  • Subtask #2 (69 point) : no additional constraints

Sample 1:

Input
Output
act
2
cat
dog
Yes
No

Explanation:

The first word can be read.

The second word contains the letters d, o and g that aren't known by Jeff.







Program :


 import java.util.*;

import java.lang.*;

import java.io.*;


/* Name of the class has to be "Main" only if the class is public. */

class Codechef

{

public static void main (String[] args) throws java.lang.Exception

{

Scanner se =new Scanner(System.in);

String str=se.next();

int n= se.nextInt();

while(n-->0)

{

int a;

a=0;

String str1=se.next();

for(int i=0;i<str1.length();i++)

{

for(int j=0;j<str.length();j++)

{

if(str1.charAt(i)==str.charAt(j)) 

    a++;

}

}

if(a==str1.length()) 

    System.out.println("Yes");

else 

    System.out.println("No");

}

}

}

Post a Comment

0 Comments