codechef prolem : Wordle Difficulty Rating:804

 

Problem

Chef invented a modified wordle.

There is a hidden word � and a guess word �, both of length 5.

Chef defines a string � to determine the correctness of the guess word. For the ��ℎ index:

  • If the guess at the ��ℎ index is correct, the ��ℎ character of � is G.
  • If the guess at the ��ℎ index is wrong, the ��ℎ character of � is B.

Given the hidden word � and guess �, determine string �.

Input Format

  • First line will contain �, number of test cases. Then the test cases follow.
  • Each test case contains of two lines of input.
  • First line contains the string � - the hidden word.
  • Second line contains the string � - the guess word.

Output Format

For each test case, print the value of string �.

You may print each character of the string in uppercase or lowercase (for example, the strings BgBgB, BGBGB, bgbGB and bgbgb will all be treated as identical).

Constraints

  • 1≤�≤1000
  • ∣�∣=∣�∣=5
  • �,� contain uppercase english alphabets only.

Sample 1:

Input
Output
3
ABCDE
EDCBA
ROUND
RINGS
START
STUNT
BBGBB
GBBBB
GGBBG

Explanation:

Test Case 1: Given string �=ABCDE and �=EDCBA. The string � is:

  • Comparing the first indices, A≠E, thus, �[1]=B.
  • Comparing the second indices, B≠D, thus, �[2]=B.
  • Comparing the third indices, C=C, thus, �[3]=G.
  • Comparing the fourth indices, D≠B, thus, �[4]=B.
  • Comparing the fifth indices, E≠A, thus, �[5]=B.
    Thus, �=BBGBB.

Test Case 2: Given string �=ROUND and �=RINGS. The string � is:

  • Comparing the first indices, R=R, thus, �[1]=G.
  • Comparing the second indices, O≠I, thus, �[2]=B.
  • Comparing the third indices, U≠N, thus, �[3]=B.
  • Comparing the fourth indices, N≠G, thus, �[4]=B.
  • Comparing the fifth indices, D≠S, thus, �[5]=B.
    Thus, �=GBBBB.
Solution:

def determine_M(S, T):
    M = ""
    for i in range(len(S)):
        if S[i] == T[i]:
            M += "G"
        else:
            M += "B"
    return M
if __name__ == "__main__":
    T = int(input())
    for _ in range(T):
        S = input().strip()
        T = input().strip()
        M = determine_M(S, T)
        print(M)

Comments

Popular posts from this blog

Compress PDF using python step by step

Empty recycle bin using python step by step

YouTube video to mp3 download using python step by step

Contact Form

Name

Email *

Message *