Đề bài
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.
Ràng buộc
0 ≤ length of text ≤ 10,000
Ví dụ
Ví dụ 1
Đầu vào:
text = "programming"
Kết quả mong đợi:
expected = "pormig"
Đầu vào:
std::string text = "programming";
Kết quả mong đợi:
std::string expected = "pormig";
Đầu vào:
string text = "programming";
Kết quả mong đợi:
string expected = "pormig";
Giải thích
Positions 0, 2, 4, 6, 8, 10 give p, o, r, m, i, g: "pormig".
Ví dụ 2
Đầu vào:
text = "a"
Kết quả mong đợi:
expected = "a"
Đầu vào:
std::string text = "a";
Kết quả mong đợi:
std::string expected = "a";
Đầu vào:
string text = "a";
Kết quả mong đợi:
string expected = "a";
Giải thích
Only position 0 exists: "a".
Tham khảo
Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.