fork download
  1. # include <iostream>
  2. # include<string>
  3. # include<cstring>
  4. using namespace std;
  5.  
  6.  
  7. int main() {
  8. // your code goes here
  9. string s,p;
  10. cin>>s;
  11. bool alphabets[26]; // Assuming your string contains charactes between a-z only.
  12. memset(alphabets,false,26);
  13. for(int i=0;i<s.size();i++)
  14. {
  15. if(alphabets[s.at(i)-'a']==false)
  16. {
  17. alphabets[s.at(i)-'a']=true;
  18. p.push_back(s.at(i));
  19. }
  20. }
  21. cout<<"Original String: "<<s<<endl;
  22. cout<<"String without duplicates: "<<p;
  23. return 0;
  24. }
Success #stdin #stdout 0.01s 5444KB
stdin
aaaaaaaabbbbcdefggghjjjj
stdout
Original String: aaaaaaaabbbbcdefggghjjjj
String without duplicates: abcdefghj