Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<string>
- #include<sstream>
- #include<algorithm>
- #include<cctype>
- #include<set>
- std::vector<std::string> readInput() {
- std::vector< std::string > words;
- std::string line;
- getline(std::cin, line);
- std::istringstream istr(line);
- std::string currWord;
- while (istr >> currWord)
- {
- words.push_back(currWord);
- }
- return words;
- }
- char toLower(char inputChar) {
- return tolower(inputChar);
- }
- void transformToLowercase(std::vector< std::string >& words) {
- for (auto& word : words)
- {
- std::transform(word.begin(), word.end(), word.begin(), toLower);
- }
- }
- std::set<std::string> produceAnswerWords(const std::vector< std::string >& words) {
- std::set<std::string> answerWords;
- for (auto& word : words)
- {
- if (word.size() < 5)
- {
- answerWords.insert(word);
- }
- }
- return answerWords;
- }
- void printSolution(const std::set<std::string>& answerWords) {
- std::ostringstream ostr;
- for (const auto& word : answerWords)
- {
- ostr << word << ", ";
- }
- std::string answerStr = ostr.str();
- if (!answerWords.empty())
- {
- answerStr.pop_back();
- answerStr.pop_back();
- }
- std::cout << answerStr << std::endl;
- }
- int main() {
- auto wordsInput = readInput();
- transformToLowercase(wordsInput);
- const auto answerWords = produceAnswerWords(wordsInput);
- printSolution(answerWords);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment