Sort by

recency

|

3404 Discussions

|

  • + 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

      Remove this "What is your name". Notice how it will be in the output with every string you input. And yea it does work.

  • + 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);
        }
    
    }
    

    }

  • + 0 comments

    test_cases = int(input()) strings = []

    for _ in range(test_cases): strings.append(input())

    for item in strings: even_index = item[0:len(item):2] odd_index = item[1:len(item):2] print(even_index,odd_index)

  • + 0 comments

    here I Got this output...

    Scanner sc=new Scanner(System.in); int n=sc.nextInt(); sc.nextLine(); for (int i = 0; i

         char[] a= str1.toCharArray();
    
          //printing the even of strings
       // System.out.println(c);
        for(int c=0;c<a.length;c++){ 
            if(c%2==0) {
               System.out.print(""+a[c]);
               }}
            System.out.print(" ");
            for(int c=0;c<a.length;c++){
            if(c%2!=0){
            System.out.print(a[c]);}
            }
            System.out.println();
        }