Sort by

recency

|

3413 Discussions

|

  • + 0 comments

    t = int(input())

    for _ in range(t): s = input() even_chars = s[::2]
    odd_chars = s[1::2]
    print(even_chars, odd_chars)

  • + 0 comments
    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=Integer.parseInt(sc.nextLine());
        for(int t=0;t<T;t++){
            String inp=sc.nextLine();
        char c[]= inp.toCharArray();
       String even="";
       String odd="";
        for(int i=0;i<c.length;i++)
        {
            if(i%2==0)
            even+=c[i];
            else
           odd+=c[i];   
        }
        System.out.println(even+" "+odd);
    }
    

    } }

  • + 0 comments

    JAVA SOLUTION

    Scanner sc = new Scanner(System.in);
            int T = sc.nextInt();
            sc.nextLine();
            for (int t = 0; t < T; t++) {
                String st = sc.nextLine();
                char[] ch = st.toCharArray();
                for (int i = 0; i < st.length(); i++) {
                    if (i % 2 == 0) {
                        System.out.print(ch[i]);
                    }
                }
                System.out.print(" ");
                for (int i = 0; i < st.length(); i++) {
                    if (i % 2 != 0) {
                        System.out.print(ch[i]);
                    }
                }
                System.out.println();
            }
    
  • + 1 comment

    My python3 solution. Let me know if there are any improvements to be made

    args = int(input().strip())
    
    for _ in range(args):
        
        text = input().strip()
        
        for i in range(len(text)):
            even = text[::2]
            odd = text[1::2]          
        print(f"{even} {odd}")
    
  • + 0 comments

    C# Solution 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 */
        //number of test cases 
        int n = Convert.ToInt32(Console.ReadLine());
    
        string[] s = new string[n];
    
        for(int i = 0; i < s.Length; i++)
        { 
            string even = string.Empty;
            string odd = string.Empty;
    
            s[i] = Console.ReadLine();
    
            /*Note that :
             string is an array of characters therefore will will convert the 's[i]' to array of 'char'.
            */
            char[] c = s[i].ToCharArray();
    
            for(int j = 0; j < c.Length ; j++)
            {
                // use modulus '%' to check remainder from the indexes
                if(j % 2 == 0)
                  even += c[j]; 
                else
                  odd += c[j];       
            }
            Console.Write($"{even} {odd}");
            Console.WriteLine();
        }    
    
    
    }
    

    }