Website Summary Files Commits Branches @commit @diff @stats
path: root / pract_SI / Pract. 08 / Stringstream / task4.cpp
diff options
context:
space:
mode:
Commit158370669b24142a71ce7778b46f5a054cafed8a (patch)
Author
 Justsvetoslavov <justsvetoslavov@gmail.com>
2021-12-26 02:42:20 +0200
Committer
 Justsvetoslavov <justsvetoslavov@gmail.com>
2021-12-26 02:42:20 +0200
Files1b7532ccf9252185bee4640413fe266b3c3c24a0 /pract_SI/Pract. 08/Stringstream/task4.cpp
Introduction_to_programming_FMI-158370669b24142a71ce7778b46f5a054cafed8a.tar
Introduction_to_programming_FMI-158370669b24142a71ce7778b46f5a054cafed8a.tar.gz
Introduction_to_programming_FMI-158370669b24142a71ce7778b46f5a054cafed8a.zip
Parenta12ab5e789509172523e59fd7a8151544d4efc3f (diff)
Add solutions
Example solutions to task4+5
1 files changed, 56 insertions, 0 deletions
-rw-r--r--pract_SI/Pract. 08/Stringstream/task4.cpp56
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 <iostream>
+#include <vector>
+#include <string>
+#include <sstream>
+
+int main() {
+ std::string str;
+ std::vector<std::pair<std::string, int>> 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<std::string> 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