fork download
  1. #include <string>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <iostream>
  5. #include <cctype>
  6.  
  7. std::string optimize(std::string toBeProcessed, std::string toBeIgnored, char ch)
  8. {
  9. std::transform(toBeProcessed.begin(), toBeProcessed.end(), toBeProcessed.begin(), ::toupper);
  10. std::transform(toBeIgnored.begin(), toBeIgnored.end(), toBeIgnored.begin(), ::toupper);
  11. std::string test;
  12. size_t start = 0;
  13. while (start < toBeProcessed.size())
  14. {
  15. size_t n = toBeProcessed.find_first_not_of(toBeIgnored, start);
  16. if ( n != std::string::npos)
  17. {
  18. toBeProcessed[n] = ch;
  19. start = n+1;
  20. }
  21. else
  22. break;
  23. }
  24. return toBeProcessed;
  25. }
  26.  
  27. int main()
  28. {
  29. std::string out = optimize("abc123", "abc1", 'x');
  30. std::cout << out;
  31. }
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
ABC1xx