Advertisement
Spocoman

02. Odd Occurrences

Jan 26th, 2024
730
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <vector>
  5. #include <map>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     string line, word;
  11.     getline(cin, line);
  12.  
  13.     istringstream ss(line);
  14.  
  15.     vector<pair<string, int>> words;
  16.  
  17.     while (ss >> word) {
  18.         for (int i = 0; i < word.length(); i++) {
  19.             word[i] = tolower(word[i]);
  20.         }
  21.  
  22.         bool isword = false;
  23.  
  24.         for (int i = 0; i < words.size(); ++i) {
  25.             if (words[i].first == word) {
  26.                 words[i].second++;
  27.                 isword = true;
  28.                 break;
  29.             }
  30.         }
  31.  
  32.         if (!isword) {
  33.             words.push_back(make_pair(word, 1));
  34.         }
  35.     }
  36.  
  37.     vector<string> output;
  38.  
  39.     for (int i = 0; i < words.size(); i++) {
  40.         if (words[i].second % 2 == 1) {
  41.             output.push_back(words[i].first);
  42.         }
  43.     }
  44.  
  45.     for (int i = 0; i < output.size(); i++) {
  46.         cout << output[i];
  47.         if (i < output.size() - 1) {
  48.             cout << ", ";
  49.         }
  50.     }
  51.  
  52.     cout << endl;
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement