Sort by

recency

|

3419 Discussions

|

  • + 0 comments

    Interesting approach using streams in Java:

    import java.io.; import java.util.; import java.util.stream.IntStream; import java.util.stream.Collectors;

    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. */
    Scanner sc = new Scanner(System.in);
    int test = sc.nextInt();
    while(test > 0 ) {
        String text = sc.next();
        String evenString = IntStream.range(0, text.length())
        .filter(i -> i%2==0)
        .mapToObj(i -> String.valueOf(text.charAt(i)))
        .collect(Collectors.joining());
    
        String oddString = IntStream.range(0, text.length())
        .filter(i -> i%2 != 0)
        .mapToObj(i -> String.valueOf(text.charAt(i)))
        .collect(Collectors.joining());
    
        System.out.println(evenString +" " + oddString);
        test--;
    }
    sc.close();
    }
    

    }

  • + 0 comments

    int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */

    int testCase;
    string Teststring;
    cin>>testCase;
    
    
    
    for(int i=0;i<testCase;i++){
        string oddString="";
        string evenString="";     
    
        cin>>Teststring;
        int len=Teststring.length();
    
    int j=0;
        while(j!=len){
    
            if(j%2==0){
                evenString=evenString+Teststring[j];
    
    
            }
            else{
                oddString=oddString+Teststring[j];
            }
            j++;
        }
        cout<<evenString<<" "<<oddString<<endl;
    
    
    }
    
    
    
    
    return 0;
    

    }

  • + 0 comments
    T = int(input())  # Number of test cases
    
    for _ in range(T):
        s = input()
        even = s[0::2]
        odd = s[1::2]
        print(even,odd,sep=" ")
    
  • + 0 comments

    Java Solution

    public class Solution {
    
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int n = sc.nextInt();
       sc.nextLine();
    
       for(int i=0;i<n;i++){
        String s = sc.nextLine();
        String oddString="";
        for(int j =0 ;j<s.length();j++){
            if(j % 2 == 0)
                System.out.print(s.charAt(j));
            else
                oddString+=s.charAt(j);
        }
        System.out.println(" "+oddString);
       }
    }
    

    }

  • + 0 comments

    My js answer :

    function processData(input) {

    const lines = input.split('\n')
    const t = parseInt(lines[0])
    
    
    for(let i = 1; i<= t; i++){
        let even = "";
        let odd = "";
    
        for(let k = 0; k < lines[i].length ; k++){
            if(k % 2 === 0){
                even += lines[i][k];
            }
            if(k % 2 === 1){
                odd += lines[i][k];
            }
        }    
    
    
         console.log(even + " " + odd);
    }
    

    }