Advertisement
mitakvd

2. Odd Occurrences

Oct 19th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <utility>
  3. #include <map>
  4. #include <sstream>
  5. #include <vector>
  6. #include <queue>
  7.  
  8. using namespace std;
  9.  
  10. void makeItLowerCases(string& input)
  11. {
  12.     if (input[0] >= '0' && input[0] <= '9')
  13.     {
  14.         input = input;
  15.     }
  16.     else
  17.     {
  18.         const int size = input.size();
  19.         for (int i = 0; i < size; i++)
  20.         {
  21.             if (input[i] >= 'A' && input[i] <= 'Z')
  22.             {
  23.                 input[i] = input[i] + 32;
  24.             }
  25.         }
  26.     }
  27. }
  28.  
  29. int main()
  30. {
  31.     string input;
  32.     getline(cin, input);
  33.     istringstream istr(input);
  34.  
  35.     string word;
  36.  
  37.     map<string, int> words;
  38.     queue<string> output;
  39.     vector<string> result;
  40.     while (istr >> word)
  41.     {
  42.         makeItLowerCases(word);
  43.  
  44.         if (words.find(word) == words.end())
  45.         {
  46.             output.push(word);
  47.         }
  48.         words[word]++;
  49.     }
  50.  
  51.     while (!output.empty())
  52.     {
  53.         string key = output.front();
  54.         if ((words.find(key)->second % 2) != 0)
  55.         {
  56.             result.push_back(key);
  57.         }
  58.         output.pop();
  59.     }
  60.     int counter = 0;
  61.     const int size = result.size();
  62.     for(string elem : result)
  63.     {
  64.         counter++;
  65.         cout << elem;
  66.         if (counter < size)
  67.         {
  68.             cout << ", ";
  69.         }
  70.     }
  71.  
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement