Sort by

recency

|

3424 Discussions

|

  • + 0 comments
    t = int(input())
    
    for _ in range(t):
        S = input().strip()
        even_index = []
        odd_index = []
    
        for i, char in enumerate(S):
            if i % 2 == 0:
                even_index.append(char)
            else:
                odd_index.append(char)
    
        print("".join(even_index), "".join(odd_index))
    
  • + 0 comments

    Here is Hackerrank Day 6: Let's Review solution in python java c++ c and javascript - https://programmingoneonone.com/hackerrank-day-6-lets-review-30-days-of-code-solution.html

  • + 0 comments

    Using stringbuilder in C#

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;
    class Solution {
        static void Main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
            int n = Convert.ToInt32(Console.ReadLine());
        
            for(int i = 0; i < n; i++) {
                string input = Console.ReadLine();
                var evenChars = new StringBuilder();
                var oddChars = new StringBuilder();
                
                for(int j = 0; j < input.Length; j++) {
                    if(j % 2 == 0)
                        evenChars.Append(input[j]);
                    else
                        oddChars.Append(input[j]);
                }
                
                Console.WriteLine($"{evenChars} {oddChars}");
            }
        }
    }
    
  • + 0 comments

    Java Logic for Printing Even & Odd's characters of a String

    Scanner sc = new Scanner(System.in);
            int T = sc.nextInt();
            String S= null ;
           for(int i=0; i<T;i++)
            {
            S= sc.next();
            
            char[] characters = S.toCharArray(); 
    
            int j=0;
            for(j=0;j<characters.length;j++)
            {
               if(j%2==0){
                   
               System.out.print(characters[j]);
               }
               
            }
            System.out.print(" ");
              
                for(j=0;j<characters.length;j++)
                {
               if(j%2==1)
               {
                       System.out.print(characters[j]);
    
               } 
            }
            System.out.println();
        
            }
            
        }
        
    
  • + 0 comments

    Python code

    for _ in range(int(input())):
        s=input()
        even=s[::2]
        odd=s[1::2]
        print(even,odd)