Alle Herausforderungen
Einfach 0 gelöst 0% Erfolgsquote

Every Other Character

Keep the characters at even positions.

Problem

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.

Einschränkungen

0 ≤ length of text ≤ 10,000

Beispiele

Beispiel 1
Eingabe:
text = "programming"

Erwartete Ausgabe:
expected = "pormig"
Eingabe:
std::string text = "programming";

Erwartete Ausgabe:
std::string expected = "pormig";
Eingabe:
string text = "programming";

Erwartete Ausgabe:
string expected = "pormig";

Erläuterung

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

Beispiel 2
Eingabe:
text = "a"

Erwartete Ausgabe:
expected = "a"
Eingabe:
std::string text = "a";

Erwartete Ausgabe:
std::string expected = "a";
Eingabe:
string text = "a";

Erwartete Ausgabe:
string expected = "a";

Erläuterung

Only position 0 exists: "a".

Referenzen

Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.

Von anderen lernen

Community-Lösungen

Noch keine veröffentlichten Lösungen. Löse die Aufgabe und teile als Erster eine Lösung.