From 158370669b24142a71ce7778b46f5a054cafed8a Mon Sep 17 00:00:00 2001 From: Justsvetoslavov Date: Sun, 26 Dec 2021 02:42:20 +0200 Subject: Add solutions Example solutions to task4+5 --- pract_SI/Pract. 08/Stringstream/task4.cpp | 56 +++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 pract_SI/Pract. 08/Stringstream/task4.cpp (limited to 'pract_SI/Pract. 08/Stringstream/task4.cpp') diff --git a/pract_SI/Pract. 08/Stringstream/task4.cpp b/pract_SI/Pract. 08/Stringstream/task4.cpp new file mode 100644 index 0000000..7b6b185 --- /dev/null +++ b/pract_SI/Pract. 08/Stringstream/task4.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +int main() { + std::string str; + std::vector> myVector; + + getline(std::cin, str); + std::stringstream ss; + ss << str; + + std::string temp; + while (ss >> temp) { + std::string lowString = ""; + bool is_exist = false; + + for (size_t i = 0; i < temp.size(); i++) + { + lowString += tolower(temp[i]); + } + + for (size_t i = 0; i < myVector.size(); i++) + { + if (myVector[i].first == lowString) + { + myVector[i].second++; + is_exist = !is_exist; + break; + } + } + + if (is_exist == false) + { + myVector.push_back(std::make_pair(lowString, 1)); + } + } + + std::vector outVector; + for (size_t i = 0; i < myVector.size(); i++) + { + if (myVector[i].second % 2 == 1) + { + outVector.push_back(myVector[i].first); + } + } + + for (size_t i = 0; i < outVector.size() - 1; i++) + { + std::cout << outVector[i] << ", "; + } + std::cout << outVector[outVector.size() - 1] << std::endl; + + return 0; +} \ No newline at end of file -- cgit v1.3.1-23-gd82d