Problem A

mail@pastecode.io avatar
unknown
csharp
2 years ago
2.7 kB
7
Indexable
Never
using System;

namespace CodingCompi
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter number of Test Cases: ");
            int numberOfCases = Convert.ToInt32(Console.ReadLine());

            for (int t = 0; t < numberOfCases; t++)
            {
                Console.WriteLine("Enter number of Countries: ");
                int numberOfCountries = Convert.ToInt32(Console.ReadLine());

                string incoming, outgoing;

                incoming = Console.ReadLine();
                outgoing = Console.ReadLine();

                char[] incomingChar = incoming.ToCharArray();
                char[] outgoingChar = outgoing.ToCharArray();

                Console.WriteLine("Case #" + (t + 1));

                for (int i = 0; i < numberOfCountries; i++)
                {
                    string output = "";
                    bool status = true;

                    for (int j = i; j > 0; j--)
                    {
                        if (!status) output += 'N';
                        else if (outgoingChar[j].Equals('N'))
                        {
                            output += 'N';
                            status = false;
                        }
                        else if (incomingChar[j - 1].Equals('Y') && outgoingChar[j].Equals('Y')) output += 'Y';
                        else
                        {
                            output += 'N';
                            status = false;
                        }
                    }

                    string reverse = output;
                    var charArray = reverse.ToCharArray();
                    Array.Reverse(charArray);
                    reverse = new string(charArray);
                    output = reverse;

                    output += 'Y';
                    status = true;

                    for (int j = i; j < numberOfCountries - 1; j++)
                    {
                        if (!status) output += 'N';
                        else if (outgoingChar[j].Equals('N'))
                        {
                            output += 'N';
                            status = false;
                        }
                        else if (incomingChar[j + 1].Equals('Y') && outgoingChar[j].Equals('Y')) output += 'Y';
                        else
                        {
                            output += 'N';
                            status = false;
                        }
                    }
                    Console.WriteLine(output);
                }
            }
        }    
    }
}