The challenge:
From: URI Online Judge
Implement a program Combiner that takes two Strings as parameters and combines them, alternating letters, starting with the first letter of the first String, followed by the first letter of the second String, then second letter of first String, etc. The remaining letters of the longer String are then appended to the end of the combination String and this combination String is returned.
Input
The input contains several test cases. The first line of input contain an integer N that indicates the number of test cases. Each test case is composed of a line containing two strings and each string contains between 1 and 50 characters, inclusive.
Output
Combine the two input strings, as shown in the example below and print the resulting string.
Code
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
while(n-- > 0)
{
args = Console.ReadLine().Split(' ');
for (int j = 0; j < args[0].Length || j < args[1].Length; j++)
{
if (j < args[0].Length)
{
Console.Write(args[0][j]);
}
if (j < args[1].Length)
{
Console.Write(args[1][j]);
}
}
Console.WriteLine();
}
}
Question is
How can this code be faster?
Apparently, my code took 0.384 second to run with URI's test cases.
The faster sample that solved the problem using C# took 0.072 second, which is a significant difference.
An image with all the execution times from this problem in C# can be found here.