Studying Alphabet Codechef Solution

Hello Programmers In this post, you will know how to solve the Studying Alphabet Codechef Solution. The Problem Code: ALPHABET

Ezoicreport this adStudying Alphabet Codechef Solution
Studying Alphabet Codechef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Problem

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.

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

act
2
cat
dog

Sample Output 1 

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.

Studying Alphabet CodeChef Solution in JAVA

import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		Set<Integer> knownLetters = S.chars().boxed().collect(Collectors.toSet());
		int N = sc.nextInt();
		for (int tc = 0; tc < N; tc++) {
			String W = sc.next();
			System.out.println(solve(knownLetters, W) ? "Yes" : "No");
		}
		sc.close();
	}
	static boolean solve(Set<Integer> knownLetters, String W) {
		return W.chars().allMatch(ch -> knownLetters.contains(ch));
	}
}

Disclaimer: The above Problem (Studying Alphabet) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: Task for Alexey Codechef Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad