fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <iterator>
  6. #include <functional>
  7. #include <cctype>
  8.  
  9.  
  10. bool has_digits(std::string const& string) {
  11. return (std::find_if(string.begin(), string.end(), ::isdigit) != string.end());
  12. }
  13.  
  14. void erase_digits(std::string & string) {
  15. string.erase(std::remove_if(string.begin(), string.end(), ::isdigit), string.end());
  16. }
  17.  
  18.  
  19. int main() {
  20. std::vector<std::string> text;
  21.  
  22. std::string tmp;
  23. for (std::size_t i = 0; (i != 10) && (std::cin >> tmp); ++i, text.push_back(tmp));
  24.  
  25. std::cout << "Strings with digits: ";
  26. std::remove_copy_if( // std::copy_if
  27. text.begin()
  28. , text.end()
  29. , std::ostream_iterator<std::string>(std::cout, " ")
  30. , std::not1(std::ptr_fun(has_digits)));
  31. std::cout << std::endl;
  32.  
  33. std::for_each(text.begin(), text.end(), erase_digits);
  34.  
  35. std::cout << "After digits removal: ";
  36. std::copy(text.begin(), text.end(), std::ostream_iterator<std::string>(std::cout, " "));
  37. std::cout << std::endl;
  38. }
Success #stdin #stdout 0s 2992KB
stdin
Look 4 c0ding conventi0ns that make wrong code 1o0k wrong
stdout
Strings with digits: 4 c0ding conventi0ns 1o0k 
After digits removal: Look  cding conventins that make wrong code ok wrong