Sort by

recency

|

3391 Discussions

|

  • + 0 comments

    T= int(input()) for i in range(T): s=input()

    even_characters = [] # For storing even characters
    odd_characters = [] # For storing odd characters
    
    for i in range(len(s)):
        if i % 2 == 0: # check if the index is even
            even_characters.append(s[i])
        else:
            odd_characters.append(s[i])
    even_characters=''.join(even_characters)
    odd_characters=''.join(odd_characters)
    res=even_characters+odd_characters
    print(res)
    
  • + 0 comments
    for C-Sharp/ [C#]
    using System;
    using System.Collections.Generic;
    using System.IO;
    class Solution {
        static void Main(String[] args) {
            int.TryParse(Console.ReadLine(), out int n);
            
            //looping for (the number of test cases).
            for(int i = 0; i<n; i++)
            {
                //Console.ReadLine C# 8 return nullable, assigned to var for easier null check
                var line = Console.ReadLine();
                //Console.ReadLine C# 8 return nullable if no line, add null check
                string rec = line != null ? line : "";
                char[] s = rec.ToCharArray();
                
                Console.WriteLine(CheckCode(s));
            }
        }
        
        static string CheckCode(char[] data)
        {
            string evenIndex = "", oddIndex = "";
            
            for(int i = 0; i< data.Length; i++)
            {
                // 0 = even and any number Modulus by 2 == 0 is even
                if (i==0 || i % 2 == 0)
                    evenIndex += data[i];
                else
                    oddIndex += data[i];
            }
            
            // return {even and odd string}
            return $"{evenIndex} {oddIndex}"; 
        }
    }
    
  • + 0 comments

    For JAVA

    Scanner scan=new Scanner(System.in);

    int N=scan.nextInt();
    scan.nextLine();
    for(int i=0;i<N;i++){
        String s=scan.nextLine();
        for(int j=0;j<s.length();j++){
            if(j%2==0){
                System.out.print(s.charAt(j));
            }
        }
        System.out.print(" ");
        for(int k=0;k<s.length();k++){
            if(k%2!=0){
                System.out.print(s.charAt(k));
            }
        }
        System.out.println();
    }
    
    scan.close();
    
  • + 0 comments

    at first glance, it works, but incorrectly... public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        String word1 = "Hacker";
        String word2 = "Rank";
    
        char[] arr1 = word1.toCharArray(); 
        char[] arr2 = word2.toCharArray(); 
        print1(arr1);
        System.out.println();
        print1(arr2);
    
    }
    
    public static void print1(char[] array) {
        for(int i = 0; i < array.length; i++) {
            if(i %2 == 0) {
                System.out.print(array[i]);
            }
        }
        System.out.print(" ");
        for(int in = 0; in < array.length; in++) {
            if(in %2 != 0){
                System.out.print(array[in]);
            }
        }
    }
    

    }

  • + 0 comments

    int main() {

    /* Enter your code here. Read input from STDIN. Print output to STDOUT */    
    int t; 
    scanf("%d", &t);
    
    while(t--)
    {
        char str[10005];
        char s1[10005];
        char s2[10005];
        scanf("%s", str);
        for(int i = 0; i < strlen(str); i++)
        {
            if(i % 2 == 0)
            {
                printf("%c", str[i]);
            }
        }
        printf(" ");
         for(int i = 0; i < strlen(str); i++)
        {
            if(i % 2 != 0)
            {
                printf("%c", str[i]);
            }
        }
        printf("\n");
    
    
    }
    return 0;
    

    }