Advertisement
Vlad3955

Unique element

Aug 16th, 2022
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <vector>
  5. #include <unordered_set>
  6.  
  7.  
  8. using namespace std;
  9.  
  10.  
  11. void unique_elements()
  12. {
  13.     int n;
  14.     string st;
  15.     unordered_multiset<int> u_set;
  16.     vector<int> vec;
  17.     stringstream ss;
  18.     getline(cin, st);
  19.     ss << st;
  20.     while (ss >> n)
  21.     {
  22.         u_set.insert(n);
  23.     }
  24.     for (auto& it : u_set)
  25.     {
  26.         if (u_set.count(it) == 1)
  27.         {
  28.             vec.push_back(it);
  29.         }
  30.     }
  31.     for (auto &it : vec)
  32.     {
  33.         cout << it << " ";
  34.     }
  35. }
  36.  
  37. int main()
  38. {
  39.     unique_elements();
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement