~ no response on stdout ~ C# Error while submitting code in HackerRank

926 views Asked by At

I am practicing C# code on HackerRank online website, when I want to submit my code then it gives an error:

enter image description here

Below is my code:

for(int i=0;i<input.Count-1;i++){
        string evenData="",oddData="";
        string data=input[i];
        for(int j=0;j<data.Length-1;j++){
            
            if(i%2==0){
                evenData += data[j].ToString();
            }else{
                oddData +=data[j].ToString();
            }
        }
        Console.WriteLine(evenData + " " +oddData);
    }

I have already search over the internet for this issue but everyone says just add Console.WriteLine because stdout and Console.writeLine both are just like same but it doesn't resolve my problem. Kindly provide me a better solution. Thanks

1

There are 1 answers

0
Zeeshan On

Use Console.In.ReadLine() and Console.Out.WriteLine() for stdin and stdout.

using System;
using System.Collections.Generic;
using System.IO;
class Solution {
    
    public static void Result(string s)
    {
        var sarry = s.ToCharArray();
        if(sarry.Length >1)
        {
            var evenstr = "";
            var oddstr  = "";
            
            for(int i=0 ;i<=sarry.Length-1 ; i++)
            {
                if(i%2==0)
                    oddstr=oddstr+sarry[i];
                else
                    evenstr=evenstr+sarry[i];
            }
            var result =oddstr+" "+evenstr;
            Console.Out.WriteLine(result);            
        }
    }
    
    static void Main(String[] args) {
        
        int T=int.Parse(Console.In.ReadLine());
        for (int i = 0; i < T; i++) 
        {
            var inp=Console.In.ReadLine();
            Solution.Result(inp);
        }
    }
}