fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. string removeDup(string s)
  8. {
  9. if (s.length() == 0)
  10. {
  11. return "";
  12. }
  13.  
  14. size_t index = 0;
  15. string::iterator end = s.end();
  16.  
  17. while (index < s.size()) {
  18. end = remove(s.begin()+index+1, end, s[index]);
  19. ++index;
  20. }
  21.  
  22. s.erase(end, s.end());
  23. return s;
  24. }
  25.  
  26. int main()
  27. {
  28. cout << removeDup("allcbbcd") << endl;
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 5656KB
stdin
Standard input is empty
stdout
alcbd