Todos los desafíos
Fácil 0 resueltos 0% de aceptación

Every Other Character

Keep the characters at even positions.

Problema

Build a new string from the characters of text at positions 0, 2, 4, … (every other character, starting with the first).

Implement every_other_character(text).

Input

text: The original text.

Output

Return the characters at even positions, in order.

Restricciones

0 ≤ length of text ≤ 10,000

Ejemplos

Ejemplo 1
Entrada:
text = "programming"

Salida esperada:
expected = "pormig"
Entrada:
std::string text = "programming";

Salida esperada:
std::string expected = "pormig";
Entrada:
string text = "programming";

Salida esperada:
string expected = "pormig";

Explicación

Positions 0, 2, 4, 6, 8, 10 give p, o, r, m, i, g: "pormig".

Ejemplo 2
Entrada:
text = "a"

Salida esperada:
expected = "a"
Entrada:
std::string text = "a";

Salida esperada:
std::string expected = "a";
Entrada:
string text = "a";

Salida esperada:
string expected = "a";

Explicación

Only position 0 exists: "a".

Referencias

Este reto está adaptado para CodeUtility. Sigue el enunciado y las restricciones indicadas arriba.

Aprende de otros

Soluciones de la comunidad

Aún no hay soluciones publicadas. Resuelve este reto para compartir la primera.