We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
using System;
using System.Collections.Generic;
using System.IO;
class Solution {
static void Main(String[] args) {
int n = Convert.ToInt32(Console.ReadLine()); // Read number of test cases (but it's unused)
// Convert string to character array
for(int i=0; i<n;i++){
string characters = Console.ReadLine();
string result=checkChar.checkindex(characters);
Console.WriteLine(result);
}
// Print result
}
class checkChar{
public static string checkindex(string characters){
// Read input string
string even = ""; // Initialize with empty string
string odd = "";
char[] chars = characters.ToCharArray();
for (int i = 0; i < characters.Length; i++) { // Fix loop (start from 0, use <)
if (i % 2 == 0) { // Check if index is even
even += chars[i];
} else {
odd += chars[i];
}
}
return even + " "+ odd;
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Day 6: Let's Review
You are viewing a single comment's thread. Return to all comments →
C# solution
using System; using System.Collections.Generic; using System.IO; class Solution { static void Main(String[] args) {
string even = ""; // Initialize with empty string string odd = "";
}