fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. string replace_num_with_x(const string &str);
  8.  
  9. int main() {
  10. cout << "Please enter a line of text:";
  11. string str;
  12. getline(cin, str);
  13. cout << replace_num_with_x(str);
  14. }
  15.  
  16. string replace_num_with_x(const string &str) {
  17. istringstream str_strm(str);
  18. ostringstream out_strm;
  19. string word;
  20.  
  21. if (str_strm >> word) {
  22. do {
  23. if (word.find_first_not_of("0123456789") == string::npos) {
  24. fill(word.begin(), word.end(), 'x');
  25. }
  26. out_strm << word;
  27. if (!(str_strm >> word)) break;
  28. out_strm << ' ';
  29. }
  30. while (true);
  31. }
  32.  
  33. return out_strm.str();
  34. }
Success #stdin #stdout 0s 4796KB
stdin
My userID is john17 and my 4 digit pin is 1234 which is secret
stdout
Please enter a line of text:My userID is john17 and my x digit pin is xxxx which is secret