30 Days of code: Day 6

https://www.hackerrank.com/domains/tutorials/30-days-of-code
Felt like there’s a better way to do this, but this was my take.

Problem was to choose how many words to read, and then output even and odd characters in the format below.
Sample Input

2
Hacker
Rank

Sample Output

Hce akr
Rn ak

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

        for (int i = 0; i < inputNumber; i++)
        {
            string s = Console.ReadLine();

            for (int x = 0; x < s.Length; x += 2)
            {
                char evenChar = s[x];
                Console.Write(evenChar);
            }
            Console.Write(" ");

            for (int x = 1; x < s.Length; x += 2)
            {
                char oddChar = s[x];
                Console.Write(oddChar);
            }
            Console.WriteLine();
        }

Leave a Reply

Your email address will not be published. Required fields are marked *