Algorithm


 problem Link : https://www.codechef.com/problems/WORDLE 

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 BgBgBBGBGBbgbGB 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.

Code Examples

#1 Code Example with C Programming

Code - C Programming

 #include<stdio.h>
int main()
{
    int t,i;
    char a[5],b[5];
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s %s",a,b);
        for(i=0;i < 5;i++)
        {
            if(a[i]==b[i])  printf("G");
            else printf("B");
        }
        printf("\n");
    }
} 
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
ABCDE
EDCBA
ROUND
RINGS
START STUNT

Output

x
+
cmd
BBGBB
GBBBB
GGBBG
Advertisements

Demonstration


CodeChef solution WORDLE  - Wordle Codechef solution in C,C++

Previous
CodeChef solution LUCKFOUR - Lucky Four Codechef solution in Codechef solution in C,C++
Next
CodeChef solution SUPCHEF - The Preparations Codechef solution in C,C++