Problem
Chef has a certain liking towards certain English characters. He considers these characters beautiful. You are given a string consisting of all the characters Chef finds beautiful.
Chef considers a word if each and every character present in the word is beautiful. Given a list of words, determine which of them are .
Input Format
- The first line of the input contains a string , consisting of beautiful characters. Each character in will appear only once.
- The second line of the input contains an integer .
- Each of the following lines contains a single string , denoting the word in the list.
Output Format
For each of the words, output "Yes" (without quotes) if the word is divine and "No" (without quotes) otherwise.
Constraints
- Each character in will appear only once.
- , consist only of lowercase English alphabets.
Subtasks
- Subtask (30 points): =
- Subtask (70 points) : Original constraints
Sample 1:
rested 3 terp dest nop
No Yes No
Explanation:
Test Case : Character isn't beautiful. Therefore this word is not divine.
Test Case : Every character in the word is beautiful. Therefore, this word is divine.
Program :
/* package codechef; // don't place package name! */
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
{
// your code goes here
Scanner sr = new Scanner(System.in);
String bchars = sr.nextLine();
int n = sr.nextInt();
String[] a = new String[n];
sr.nextLine();
for (int i = 0; i < n; i++)
{
a[i] = sr.nextLine();
}
for (String s: a)
{
boolean d = true;
for (char c: s.toCharArray())
{
if (!bchars.contains("" + c))
{
d = false;
break;
}
}
if (d)
System.out.println("Yes");
else
System.out.println("No");
}
}
}
0 Comments