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 { namespace fundamentals {
auto join_words(const std::vector<std::string>& words, char separator) -> std::string { auto join_words(const std::vector<std::string>& words, const char separator) -> std::string {
// TODO: Join words with separator, no trailing separator. std::ostringstream oss;
(void)words; size_t i = 0;
(void)separator; for (const auto& word : words) {
return {}; i++;
oss << word;
if (i < words.size()) {
oss << separator;
}
}
return oss.str();
} }
auto parse_integers(const std::string& csv) -> std::vector<int> { auto parse_integers(const std::string& csv) -> std::vector<int> {
// TODO: Parse comma-separated integers (e.g. "1,2,3"). std::vector<int> numbers;
(void)csv; std::istringstream iss(csv);
return {}; 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 { auto format_score(const std::string& player, const int score) -> std::string {
// TODO: Return "<player> scored <score> points". std::ostringstream oss;
(void)player; oss << player << " scored " << score << " points";
(void)score; return oss.str();
return {};
} }
} // namespace fundamentals } // namespace fundamentals