# HackerRank Solutions – 30 Days of Code – Day 6

OBJECTIVE:
Given a string, SS, of length NN that is indexed from 00 to N−1N−1, print its even-indexed and odd-indexed characters as 22 space-separated strings on a single line (see the Sample below for more detail).

Note: 00 is considered to be an even index.

Input Format

The first line contains an integer, TT (the number of test cases).
Each line ii of the TT subsequent lines contain a String, SS.

Constraints

• 1≤T≤101≤T≤10
• 2≤length of S≤100002≤length of S≤10000

Output Format

For each String SjSj (where 0≤j≤T−10≤j≤T−1), print SjSj‘s even-indexed characters, followed by a space, followed by SjSj‘s odd-indexed characters.

Sample Input

2

Hacker

Rank

Sample Output

Hce akr

Rn ak

Explanation

Test Case 0: S=“Hacker”
S=“H”
S=“a”
S=“c”
S=“k”
S=“e”
S=“r”
The even indices are 0, 2, and 4, and the odd indices are 1, 3, and 5. We then print a single line of 2 space-separated strings; the first string contains the ordered characters from S‘s even indices (Hce), and the second string contains the ordered characters from S‘s odd indices (akr).

Test Case 1: S=“Rank”
S=“R”
S=“a”
S=“n”
S=“k”
The even indices are 0 and 2, and the odd indices are 1 and 3. We then print a single line of 2 space-separated strings; the first string contains the ordered characters from S‘s even indices (Rn), and the second string contains the ordered characters from S‘s odd indices (ak).

PROGRAM:

#include <stdio.h>
#include <stdlib.h>

int main() {

int t;
scanf(“%d”,&t);
while(t)
{
char a;
scanf(“%s”,a);
int i=0;
while(a[i]!=’\0′)
{if(i%2==0)
printf(“%c”,a[i]);
i++;}
i=0;
printf(” “);
while(a[i]!=’\0′)
{if(i%2!=0)
printf(“%c”,a[i]);
i++;}
t–;
printf(“\n”);
}
return 0;
}

OUTPUT:

Congratulations!

You have passed the sample test cases. Click the submit button to run your code against all the test cases.

Input (stdin)
``````2
Hacker
Rank``````
``````Hce akr
``````Hce akr