Thef and his games || Thef Loves Letter 'T' || Thef to Win the game

Thef and his games:

In a far away Galaxy of Tilky Way, there was a planet Tarth where the sport of Tompetitive Toding was very popular. According to legends, there lived a setter known to give advanced string manipulation problems disguised as cakewalk problems.

thef, the king of thefland loved the letter 't'. And now, he has made a game on it with his ministers! His ministers would give him 2 strings, a and b. thef has to make them exactly same, for which he can do the following-

Step 1 - He MAY reverse at most one of the strings. (This step is optional, and he can choose to reverse any one of the strings, or leave both of them as it is.)

Step 2 - He replaces the first character of both the current strings to 't'. This operation is compulsory.

He wins if he is able to make both the strings same (i.e. an exact match) after doing these two steps. Given the strings a and b, tell if thef can win or not!


Input:

The first line contains the 2 strings, a and b separated by a single space.Output:

Print Yes if thef wins, else print No


Constraints

1≤lal,lbl≤100, where lal refers to the length of string a.

⚫ a and b will have ONLY lower case English alphabets


Sample 1:

Input:

man nam

Output:

Yes


Explanation:

you can reverse man to nam and then replace both first characters of

both strings to get tam. You could also have reversed nam to man,

and then replaced the first two characters to get tan. Either of these

two methods leads thef to win the game.


Sample 2:

Input:

abd ebf

Output:

No

Explanation:

The 2 strings cannot be made equal in this case.


Sample input E

abcd ebcd

Sample output

Yes


Program:


#c

#include <stdio.h>

#include <string.h>

int main() {

    char a[101], b[101];

    scanf("%s %s", a, b);

    a[0] = 't';

    b[0] = 't';

    if(strcmp(a, b) == 0) 

        printf("Yes");

    else

        printf("No");

}


#Python

a, b = input().split()

a = 't' + a[1:]

b = 't' + b[1:]

if a == b:

    print("Yes")

else:

    print("No")






Explanation:

        This code takes two strings as input, extracts the second character from each string and replaces the first character with the letter 't'. It then checks if the modified strings are equal, and if so, prints "Yes", otherwise, it prints "No".

Here's a step-by-step explanation of what the code does:

1.a, b = input().split() - This line takes input from the user in the form of two strings separated by a space and assigns them to the variables a and b, respectively.

2.a = 't' + a[1:] - This line extracts the second character from the string a using the slice notation a[1:] (which means "all characters from the second position onwards") and concatenates it with the letter 't'. The resulting string is then assigned back to a.

3.b = 't' + b[1:] - This line does the same thing as the previous line, but for the string b.

4.if a == b: - This line checks if the modified strings a and b are equal using the == operator.

5.print("Yes") - If the strings are equal, this line prints the string "Yes" to the console.

6.else: - If the strings are not equal, this line starts the else block.

7.print("No") - This line prints the string "No" to the console.

Post a Comment

0 Comments