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.
usingSystem;usingSystem.Collections.Generic;usingSystem.IO;classSolution{staticvoidMain(String[]args){int.TryParse(Console.ReadLine(),outintn);//looping for (the number of test cases).for(inti=0;i<n;i++){//Console.ReadLine C# 8 return nullable, assigned to var for easier null checkvarline=Console.ReadLine();//Console.ReadLine C# 8 return nullable if no line, add null checkstringrec=line!=null?line:"";char[]s=rec.ToCharArray();Console.WriteLine(CheckCode(s));}}staticstringCheckCode(char[]data){stringevenIndex="",oddIndex="";for(inti=0;i<data.Length;i++){// 0 = even and any number Modulus by 2 == 0 is evenif(i==0||i%2==0)evenIndex+=data[i];elseoddIndex+=data[i];}// return {even and odd string}return$"{evenIndex} {oddIndex}";}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 6: Let's Review
You are viewing a single comment's thread. Return to all comments →