Sort by

recency

|

3406 Discussions

|

  • + 0 comments

    solution in java

    Scanner scanner = new Scanner (System.in); StringBuilder even = new StringBuilder(); StringBuilder odd = new StringBuilder();

    int t= scanner.nextInt();
    scanner.nextLine();
    for(int i=0; i<t;i++){
        String testCase = scanner.nextLine();
    
        for(int j=0;j<testCase.length();j++){
            if(j%2==0){
                even.append(testCase.charAt(j));
            }else{
                odd.append(testCase.charAt(j));
            }
        }
        System.out.println(even.toString().trim() + " " + odd.toString().trim());
        even.setLength(0);
        odd.setLength(0);
    
    }
    
    scanner.close();
    
  • + 0 comments

    solution in python 3:

    n = int(input())
    for _ in range(n):
        a= ""
        b= ""
        S = str(input())
        for i in range(len(S)):
            if i%2 == 0:
                a += S[i]
            elif i%2 !=0:
                b+= S[i]
        print(a+" "+b)
    
  • + 0 comments

    C# solution

    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;
    
        }
    }
    

    }

  • + 1 comment

    n = str(input("What is your name")) a = "" b = "" for x in range(len(n)): if x%2 == 0: a+=n[x] elif x%2 != 0: b+=n[x] print(a+""+b)

    This is my code. it gives right output in pycharm but why cant i pass the test cases?/ anyoone please help

  • + 0 comments

    **SUCCESSFULLY COMPLETED THIS PROGRAM ** PLEASE LET ME KNOW, TO OPTIMIZE THIS!!

    // import java.io.; import java.util.;

    public class Solution {

    public static void Testcase(String s)
    {
        char[] ch = s.toCharArray();
        char[] ab = new char[5000];
         char[] bc = new char[5000];
    
        int g=0;
        int h=0;
    
        for(int i=0;i<s.length();i++)
        {
            if(i%2==0)
            {
                ab[g++]=ch[i];
            }
            else
            {
                bc[h++]=ch[i];
            }
        }
        System.out.println(new String(ab,0,g)+" "+new String(bc,0,h));
    
    }
    
    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 a = sc.nextInt();
        String s;
    
        for(int j=1;j<=a;j++)
        {
            s = sc.next();
            Testcase(s);
        }
    
    }
    

    }