Codechef : Problem name " DNA Storage " solution in C#

 ============================Problem Statement=============================

For encoding an even-length binary string into a sequence of ATC, and G, we iterate from left to right and replace the characters as follows:

  • 00 is replaced with A
  • 01 is replaced with T
  • 10 is replaced with C
  • 11 is replaced with G

Given a binary string  of length  ( is even), find the encoded sequence.

Input Format

  • First line will contain , number of test cases. Then the test cases follow.
  • Each test case contains two lines of input.
  • First line contains a single integer , the length of the sequence.
  • Second line contains binary string  of length .

Output Format

For each test case, output in a single line the encoded sequence.

Note: Output is case-sensitive.

===========================Solution in C#========================

using System;

public class Test

{

public static void Main()

{

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

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

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

    string S= Console.ReadLine();

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

                {

                    if ((S[j] == '0') && (S[j + 1] == '0'))

                    {

                        Console.Write("A");

                    }

                    else if ((S[j] == '0') && (S[j + 1] == '1'))

                    {

                        Console.Write("T");

                    }

                    else if ((S[j] == '1') && (S[j + 1] == '0'))

                    {

                        Console.Write("C");

                    }

                    else

                    {

                        Console.Write("G");

                    }

                }

   Console.WriteLine();

}

}

}

========================Explanation==================
We are taking the input
When there is consecutive digits as per condition we are just checking in the string, we are printing output accordingly

Comments