fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector<char> first_unique(vector<char> stream){
  5. unordered_map<char, int> count;
  6. queue<char> q;
  7. vector<char> result;
  8. for(char c: stream){
  9. count[c]++;
  10. q.push(c);
  11. while(!q.empty() && count[q.front()] > 1){
  12. q.pop();
  13. }
  14. if(!q.empty()){
  15. result.push_back(q.front());
  16. }
  17. else result.push_back('#');
  18. }
  19. return result;
  20. }
  21.  
  22. int main(){
  23. vector<char> input = {'a', 'b', 'c', 'd', 'e'};
  24. vector<char> ans = first_unique(input);
  25.  
  26. for (char ch : ans) {
  27. cout << ch << " ";
  28. }
  29.  
  30. return 0;
  31.  
  32. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
a a a a a