Question

In: Computer Science

Girl? Jojo is looking for his love by sending messages to strangers on a dating application....

Girl?

Jojo is looking for his love by sending messages to strangers on a dating application. Because he knows that many people are using fake profile photos, he found a way to find out the gender of the user by their user names. If the number of distinct characters in one’s user name is even, then she is a female, otherwise he is a male. Help him to find out their gender! '

Format Input:

The first line is an integer T representing the number of test cases. The next T lines each consist of a string S representing the user name in the dating application.

Format Output:

For each test case output “Case #X: ”, where X is the case number, followed by “Yay” if the user is a female, or “Ewwww” if the user is a male.

Constraints

• 1 ≤ T ≤ 100

• 1 ≤ |S| ≤ 105

• S only consist of lowercase letter.

Sample Input 1 (standard input):

1

abb

Sample Output 1 (standard output):

Case #1: Yay

Sample Input 2 (standard input):

2

abbc

za

Sample Output 2 (standard output):

Case #1: Ewwww

Case #2: Yay

Note:

On the first sample input, first test case, the user is female because there are 2 different letters namely “a” and “b”, so the output is “Yay”.

note : USE C language, integer must be the same as the constraint, DONT USE VOID, RECURSIVE(RETURN FUNCTION), RESULT, code it under int main (must be blank){

Solutions

Expert Solution

Algorithm:

  1. First of all, we have declared an array of size 26 and set all the elements as 0.
  2. Taken the test case as an input.
  3. Taken the input string as input.
  4. Now traverse the entire string and for every element increased the corresponding counter value by one.
  5. Here, the counter of 'a' is 0th index, for 'b', it's 1st element and so on.
  6. After the traversal, we start traversing the 26-element array which we had declared in the first step and checked, how many counters are greater than 0.
  7. If the total number of counters which are greater than 0 is even then printed "Yay" and in other case printed "Ewwww"
  8. Computation for the first test case ended.

Please refer to the comments of the program for more clarity.

#include<stdio.h>

int main()
{
    // Declared the variables
    int t,i,k,unique_counter;
    int alphabet_counter[26];
    // Declared the char array for taking input
    char input_string[100000];

    // Taken the number of test cases
    scanf("%d",&t);

    // Started the loop
    for(k=1;k<=t;k++)
    {
        scanf("%s",&input_string);

        // Initializing the unique counter
        unique_counter = 0;

        // Resetting the alphabet counter to 0
        for(i=0;i<26;i++)
        {
            alphabet_counter[i] = 0;
        }
        for(i=0;i<strlen(input_string);i++)
        {
            alphabet_counter[input_string[i]-97]++; // ASCII value of a = 97, b = 98 , and so on
        }


        // increasing the counter when that alphabet was present
        for(i=0;i<26;i++)
        {
            if(alphabet_counter[i] > 0)
                unique_counter++;
        }

        // Checking if the number of unique alphabets are even or not
        if(unique_counter%2 == 0)
        {
            printf("Case #%d: ", k);
            printf("Yay\n");
        }
        else  // When number of unique alphabets are odd
        {
            printf("Case #%d: ", k);
            printf("Ewwww\n");
        }

    }
    return 0;
}

Sample Input-Output/CodeRun - 1:

Sample Input-Output/CodeRun - 2:

Please let me know in the comments in case of any confusion. Also, please upvote if you like.


Related Solutions

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT