/
Ikocs
/
cpp-tasks
Обзор
Документация
Войти
/
Ikocs
/
cpp-tasks
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
12_spinWords/main.cpp
51 строка
948 B
Alexey Elfimov
Init commit
16 сен 2024, 14:45
16 сен 2024, 14:45
08b7ab0
Код
Авторство
О чём код?
#include <iostream> #include <sstream> #include <vector> #include <algorithm> std::string spinWords(const std::string &str) { if (str.size() < 5) return str; std::stringstream ss(str); std::vector<std::string> words; std::string word; while (std::getline(ss, word, ' ')) words.push_back(word); std::string result; for (auto w : words) { if (w.size() >= 5) { std::reverse(w.begin(), w.end()); } result += w + " "; } result.pop_back(); return result; }// spinWords std::string spinWords2(const std::string &str) { std::stringstream ss(str); std::string result; std::string buff; while (ss >> buff) { if (buff.size() >= 5) { std::reverse(buff.begin(), buff.end()); } result += buff + ' '; } result.pop_back(); return result; } int main() { std::cout << spinWords("Hey fellow warriors") << std::endl; return 0; }