fork download
  1. #include <stdlib.h>
  2. #include<iostream>
  3. #include<unordered_map>
  4. using namespace std;
  5.  
  6.  
  7. char *removeDirtyChars(char *str, char *mask_str)
  8. {
  9. unordered_map<char , bool> mp;
  10. for (int i = 0; mask_str[i]; i++){
  11. mp[ mask_str[i] ] = 1;
  12. }
  13.  
  14. int ip_ind = 0, res_ind = 0;
  15. while ( str[ip_ind] )
  16. {
  17. char temp = str [ip_ind];
  18. if (mp[temp] == 0)
  19. str [res_ind++] = str [ip_ind];
  20. ip_ind++;
  21. }
  22.  
  23. str[res_ind] = '\0';
  24. return str;
  25. }
  26.  
  27. int main()
  28. {
  29.  
  30. char str[] = "geeksforgeeks";
  31. char mask_str[] = "mask";
  32. cout<< removeDirtyChars(str, mask_str) <<endl;
  33. return 0;
  34. }
Success #stdin #stdout 0s 4388KB
stdin
Standard input is empty
stdout
geeforgee