In this HackerRank Day 6: Let's Review problem solution Given a string, S, of length N that is indexed from 0 to N - 1, print its even-indexed and odd-indexed characters as 2 space-separated strings on a single line (see the Sample below for more detail).

HackerRank Day 6: Let's Review problem solution

Problem solution in Python programming.

n = int(input())
for t in range(n):
    s = input()
    s1 = ""
    s2 = ""
    for i in range(len(s)):
        if i%2==0:
            s1 += s[i]
        else:
            s2 += s[i]
    print(s1, s2)



Problem solution in Java programming.

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for (int i = 0; i < T; i++) {
            String s = sc.next();
            char[] c = s.toCharArray();
            int k = 0;
            boolean funny = true;
            for(int j = (c.length-1); j > 0; j--){
                if( Math.abs(c[j] - c[j-1]) != Math.abs(c[k] - c[k+1])){
                    funny = false;
                    break;
                }
                k++;
            }
            if(funny){
                System.out.println("Funny");
            }else{
                System.out.println("Not Funny");
            }
        }
        sc.close();
    }
}



Problem solution in C++ programming.

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        string a;
        cin >> a;
        string ar = a;
        reverse(ar.begin(), ar.end());
        int l = a.length();
        int k = 1;
        for(int j = 1; j < l; j++){ 
            if(abs(int(a[j]) - int(a[j - 1])) != abs(int(ar[j]) - int(ar[j - 1]))){
                k = 0;
                break;
            }
        }
        if(k == 1){
            cout << "Funny" << endl;
        }
        else{
            cout << "Not Funny" << endl;
        }
    }
    return 0;
}


Problem solution in C programming.

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

int main() {
    int n;    
    scanf("%d",&n);
    int c = 1;
    while(c<=n){
        char input[90000];
        scanf("%s",input);
        int l = strlen(input);
        int i=0;
        while(i<l){        
        printf("%c",input[i]);
        i=i+2;
        }
        i = 1;
        printf(" ");
        while(i<l){        
        printf("%c",input[i]);
        i=i+2;  
      
       }
       c++;
       printf("\n");
    }

    
    
    return 0;
}


Problem solution in Javascript programming.

function processData(input) {
    //Enter your code here
    var arr = input.split('\n');
    
    
    for (i=1;i<arr.length;i++) {
        var myArr = arr[i].split('');
        var even = [];
        var odd = [];
        for (j=0;j<myArr.length;j++) {
            if (j%2==0) {
                even.push(myArr[j]);
            } else {
                odd.push(myArr[j]);
            }
        }
        even = even.join('');
        odd = odd.join('');
        console.log(even + " " + odd);
    }
} 

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
   processData(_input);
});