Sort by

recency

|

3395 Discussions

|

  • + 0 comments

    def string(s): even_char = s[::2] odd_char = s[1::2] return f"{even_char} {odd_char}" t = int(input()) for i in range(t): s = input() print(string(s))

  • + 0 comments

    My solution in C may not be the optimal one, but I enjoyed coding it

    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <stdlib.h>
    
    void procesar_cadena(char* str) {
        
        size_t lon = strlen(str);
        
        // Crear dos cadenas auxialiares para, impar
        char* str_p = malloc(sizeof(char)*lon);
        char* str_i = malloc(sizeof(char)*lon);
    
        if (!str_p || !str_i) exit(1);
    
        // Iterar sobre cadena original para copiar en las posiciones pares e impares
        int i=0, j=0;
        for(int k=0; k<strlen(str); k++){
            
            if (k%2 == 0) str_p[i++] = str[k]; 
            else str_i[j++] = str[k];
    
        }
        
        // Agregar 0 terminador cadena
        str_p[i] = 0; str_i[j] = 0;
    
        // Formatear salida original
        sprintf(str, "%s %s", str_p, str_i);
        
        // Liberar memoria;
        free(str_p); free(str_i);
            
    }
    
    int main() {
    
        // Leer numero de strings y limpiar buffer
        int num_cad = 0;
        scanf("%d", &num_cad);
        int c;
        while((c=getchar()) != '\n') {}
        
        char* cadenas[num_cad];    // Crear tantas cadenas como n num_cad
        char *linea = NULL;             // Buffer para almacenar la entrada
        size_t lon = 0;                     // Longitud cadena de entrada
            
        // Leer la entrada y almacenarlo en cada cadena
        for (int i=0; i<num_cad; i++) {
            
            // Leer la entrada con getline para manejar longitud de cadena desconocida
            if(getline(&linea, &lon, stdin) == -1) exit(1); 
                
            linea[strcspn(linea, "\n")] = 0;               // Limpiar salto de linea
            
            cadenas[i] = malloc(sizeof(char)*lon);  // Asignar memoria a cadenas
            strcpy(cadenas[i], linea);                      // Copiar el contenido de entrada a cadenas
            
        }
        
        // Procesar cadenas
        for (int i=0; i<num_cad; i++) {
            procesar_cadena(cadenas[i]);
        }
        
        // Printear cada cadena
        for (int i=0; i<num_cad; i++) {
            puts(cadenas[i]);
        }
        
        
        // Liberar memoria
        for (int i=0; i<num_cad; i++) {
            free(cadenas[i]);
        }
             
        return 0;
    }
    
  • + 0 comments
    const lines = input.split('\n');
        const n = parseInt(lines[0], 10);
    
        for (let i = 1; i <= n; i++) {
            let evenStr = "";
            let oddStr = "";
            for (j = 0; j <= lines[i].length - 1; j++) {
                if (j % 2 === 0) {
                    evenStr = evenStr + lines[i][j]
                } else {
                    oddStr = oddStr + lines[i][j]
                }
            }
            console.log(evenStr,oddStr)
        }
    
  • + 0 comments

    the solution T= int(input()) for i in range(T): s=input() even_characters = [] # For storing even characters odd_characters = [] # For storing odd characters

    for j in range(len(s)):
        if j % 2 == 0: # check if the index is even
            even_characters.append(s[j])
        else:
            odd_characters.append(s[j])
    even_characters=''.join(even_characters)
    odd_characters=''.join(odd_characters)
    print(even_characters, odd_characters)
    
  • + 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)