Studying Alphabet Solution

 Studying Alphabet

Not everyone probably knows that Chef has younder 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.

report this adThe 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 W

i

, 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 Input 1

act
2
cat
dog

Sample Output 1

Yes
No





 Program:
import sys

S = input()
kl = set(ord(ch) for ch in S)

N = int(input())
for i in range(N):
    W = input()
    if all(ord(ch) in kl for ch in W):
        print("Yes")
    else:
        print("No")







Explanation:
This code takes a string S as input and converts its characters into a set of integer values using the ord() function. It then takes an integer N as input and iterates N times. In each iteration, it reads a string W as input and checks if all of its characters are present in the kl set by checking their integer values using the ord() function. If all the characters are present, it prints "Yes", otherwise it prints "No".

The solve() function is not used in the Python code since its purpose is only to check if a given string contains all the characters in the kl set, which can be done using the all() function in Python.

Post a Comment

0 Comments