Divine Words Solution

Problem

Chef has a certain liking towards certain English characters. He considers these characters beautiful. You are given a string S consisting of all the characters Chef finds beautiful.

Chef considers a word divine if each and every character present in the word is beautiful. Given a list of N words, determine which of them are divine.

Input Format

  • The first line of the input contains a string S, consisting of beautiful characters. Each character in S will appear only once.
  • The second line of the input contains an integer N.
  • Each of the following N lines contains a single string P_i, denoting the i^{th} word in the list.

Output Format

For each of the N words, output "Yes" (without quotes) if the word is divine and "No" (without quotes) otherwise.

Constraints

  • 1 \leq |S| \leq 26
  • 1 \leq N \leq 1000
  • 1 \leq |P_i| \leq 12
  • Each character in S will appear only once.
  • SP_i consist only of lowercase English alphabets.

Subtasks

  • Subtask 1 (30 points): |S| = 1
  • Subtask 2 (70 points) : Original constraints

Sample 1:

Input
Output
rested
3
terp
dest
nop
No
Yes
No

Explanation:

Test Case 1: Character p isn't beautiful. Therefore this word is not divine.

Test Case 2: Every character in the word d, e, s, t is beautiful. Therefore, this word is divine.






Program :


 #include <stdio.h>

#include<string.h> 

int main(){

    char s[26]; 

    scanf("%s",s); 

    int t; 

    scanf("%d\n",&t); 

    while(t-->0) 

    {  

        char a[26]; 

        scanf("%s",a); 

        int i,j,count=0; 

        for(i=0;i<strlen(a);i++) 

        {

            for(j=0;j<strlen(s);j++) 

            {

                if(a[i]!=s[j])

                {

                    count==0; 

                    }

                    else 

                    {

                        count++; 

                        break; 

                        }

                        }  

                        }

                        if(count==strlen(a)) 

                        {

                            printf("Yes\n"); 

                            }

                            else

                            {

                                printf("No\n"); }  

                                } 

    return 0; 

}

Post a Comment

0 Comments