Tous les défis
Facile 0 résolus 0 % de réussite

Every Other Character

Keep the characters at even positions.

Problème

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.

Contraintes

0 ≤ length of text ≤ 10,000

Exemples

Exemple 1
Entrée :
text = "programming"

Sortie attendue :
expected = "pormig"
Entrée :
std::string text = "programming";

Sortie attendue :
std::string expected = "pormig";
Entrée :
string text = "programming";

Sortie attendue :
string expected = "pormig";

Explication

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

Exemple 2
Entrée :
text = "a"

Sortie attendue :
expected = "a"
Entrée :
std::string text = "a";

Sortie attendue :
std::string expected = "a";
Entrée :
string text = "a";

Sortie attendue :
string expected = "a";

Explication

Only position 0 exists: "a".

Références

Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.

Apprenez des autres

Solutions de la communauté

Aucune solution publiée pour l'instant. Résolvez ce défi pour partager la première.