Solved: 01 - Basic IO

This commit is contained in:
David Gil de Gómez Pérez
2026-08-11 17:56:35 +03:00
parent 9aed1d1d86
commit 8de2e83c0b
+25 -13
View File
@@ -5,24 +5,36 @@
namespace fundamentals {
auto join_words(const std::vector<std::string>& words, char separator) -> std::string {
// TODO: Join words with separator, no trailing separator.
(void)words;
(void)separator;
return {};
auto join_words(const std::vector<std::string>& words, const char separator) -> std::string {
std::ostringstream oss;
size_t i = 0;
for (const auto& word : words) {
i++;
oss << word;
if (i < words.size()) {
oss << separator;
}
}
return oss.str();
}
auto parse_integers(const std::string& csv) -> std::vector<int> {
// TODO: Parse comma-separated integers (e.g. "1,2,3").
(void)csv;
return {};
std::vector<int> numbers;
std::istringstream iss(csv);
int n;
char c;
do {
iss >> n;
numbers.push_back(n);
iss >> c;
} while (!iss.eof());
return numbers;
}
auto format_score(const std::string& player, int score) -> std::string {
// TODO: Return "<player> scored <score> points".
(void)player;
(void)score;
return {};
auto format_score(const std::string& player, const int score) -> std::string {
std::ostringstream oss;
oss << player << " scored " << score << " points";
return oss.str();
}
} // namespace fundamentals