Codechef : Problem name " Wordle " solution in C#

===============================Solution========================== 

using System;

using System.Text;

public class Test

{

public static void Main()

{

    int t=Convert.ToInt32(Console.ReadLine());

for(int i=0;i<t;i++){

    string S=Console.ReadLine();//hidden

    string T=Console.ReadLine();//guess

    StringBuilder M=new StringBuilder();

    

    for(int j=0;j<S.Length;j++)

    {

        if(T[j]==S[j])

        {

            M.Append('G');

        }

        else{

            M.Append('B');

        }

    }

    Console.WriteLine(M.ToString());

}

}

}

============================Explanation=========================

We have taken stringbuilder so that after operations like comparing characters of both strings S and T we will create the required string out of stringbuilder

Here we are comparing character wise the hidden string and the guessed string 

if character of hidden string and guessed string is matching then we will append 'G' to the stringbuilder M 

if character of hidden string and guessed string is not matching then we will append 'B' to the stringbuilder M

Comments