Header Ads Widget

Wordle | codechef solution

 

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

  • 11000
  • ==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, AE, thus, [1]=B.
  • Comparing the second indices, BD, thus, [2]=B.
  • Comparing the third indices, C=C, thus, [3]=G.
  • Comparing the fourth indices, DB, thus, [4]=B.
  • Comparing the fifth indices, EA, 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, OI, thus, [2]=B.
  • Comparing the third indices, UN, thus, [3]=B.
  • Comparing the fourth indices, NG, thus, [4]=B.
  • Comparing the fifth indices, DS, thus, [5]=B.
    Thus, =GBBBB.
Code(c++):-
#include <iostream>
using namespace std;

int main() {
    // your code goes here
    int t;
    cin>>t;
    while(t--)
    {
     string a,b,c="";
     cin>>a>>b;
     for(int i=0;a[i];i++)
     {
     if(a[i]==b[i])
     c+="G";
     else
     c+="B";
     }
     cout<<c<<endl;
    }
    return 0;
}


Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-



Post a Comment

0 Comments