Sort by

recency

|

3388 Discussions

|

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

    }

  • + 0 comments

    In Python:

    def index_characters(string):
        evens = [letter for index, letter in enumerate(string) if index % 2 == 0]
        odds = [letter for index, letter in enumerate(string) if index % 2 != 0]
        print("".join(evens), "".join(odds))
        
    if __name__ == "__main__":
        n = int(input())
        
        for _ in range(n):
            string = input()
            index_characters(string)
    
  • + 0 comments
    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner in=new Scanner(System.in);
            int n=in.nextInt();
            String s;
            for(int i=1;i<=n;i++)
            {
                s=in.next();
                for(int j=0;j<s.length();j=j+2){
                    System.out.print(s.charAt(j));
                }
                System.out.print(" ");
                for(int k=1;k<s.length();k=k+2){
                    System.out.print(s.charAt(k));
                }
                 System.out.println();
            }
           
            
        }
    }
    
  • + 0 comments

    In Python

    def test_case(): s = input() e=[] o=[] for k in range(len(s)): if k%2==0:
    e.append(s[k]) else: o.append(s[k]) s= f"{"".join(e)} {"".join(o)}" return s

    for i in range(int(input())): print(test_case())