Advertisement
cska1312

02. Odd Occurrences

May 11th, 2023
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <climits>
  3. #include <stack>
  4. #include <string>
  5. #include <vector>
  6. #include <sstream>
  7. #include <list>
  8. #include <algorithm>
  9. using namespace std;
  10.  
  11. char tolower_char(char c)
  12. {
  13.   return tolower(c);
  14. }
  15.  
  16. int main()
  17. {
  18.   string buffer;
  19.   getline(cin, buffer);
  20.  
  21.   istringstream istr(buffer);
  22.  
  23.   string word;
  24.   list< pair<string, size_t> > words;
  25.   while(istr >> word)
  26.     {
  27.       transform(word.begin(), word.end(), word.begin(), tolower_char);
  28.       bool found = false;
  29.       for(auto & elem : words)
  30.         {
  31.           if(elem.first == word)
  32.           {
  33.           elem.second++;
  34.           found = true;
  35.           break;
  36.         }
  37.     }
  38.   if(!found)
  39.     words.push_back( pair<string, size_t>(word, 1) );
  40.     }
  41.   bool firstWord = true;
  42.   for(auto item : words)
  43.     {
  44.       if(item.second %2 )
  45.       {
  46.         if(!firstWord)
  47.           cout << ", ";
  48.             else
  49.           firstWord = false;
  50.           cout << item.first;
  51.       }
  52.     }
  53.   return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement