fork(2) download
  1. #include <algorithm>
  2. #include <cstring>
  3. #include <iostream>
  4. #include <string>
  5.  
  6. const char default_disallowed[] = {
  7. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  8. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  9. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1,
  10. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
  11. 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0,
  13. 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
  15. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  16. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  17. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  18. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  19. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  20. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  21. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  22. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  23. };
  24.  
  25. void remove_disallowed(std::string &str, const char *lookup = default_disallowed)
  26. {
  27. str.erase(std::remove_if(str.begin(), str.end(), [&](char c) {
  28. return lookup[static_cast<unsigned char>(c)];
  29. }), str.end());
  30. }
  31.  
  32. // make disallow table from complement of "good" character string
  33. void make_disallowed(const std::string &str, char *lookup) // lookup[256]
  34. {
  35. memset(lookup, 1, 256);
  36. for (unsigned char c : str) {
  37. lookup[c] = 0;
  38. }
  39. }
  40.  
  41. int main()
  42. {
  43. char table[256];
  44. make_disallowed("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-", table);
  45.  
  46. std::string str;
  47. while (std::getline(std::cin, str)) {
  48. //remove_disallowed(str);
  49. remove_disallowed(str, table);
  50. std::cout << str << '\n';
  51. }
  52. }
  53.  
Success #stdin #stdout 0s 3436KB
stdin
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
stdout
-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz