Solved: 01 - Basic IO
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user