fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. int main() {
  5. const std::string numbers[] = {
  6. "zero",
  7. "one",
  8. "two",
  9. "three",
  10. "four",
  11. "five",
  12. "six",
  13. "seven",
  14. "eight",
  15. "nine"
  16. };
  17.  
  18. const int MAX_LINES = 30;
  19. std::string line[MAX_LINES];
  20.  
  21. int i = 0;
  22. while (i < MAX_LINES && std::getline(std::cin, line[i])) {
  23. ++i;
  24. }
  25.  
  26. int numLines = i;
  27.  
  28. for (i = 0; i < numLines; ++i) {
  29. for (int num = 0; num < 10; ++num) {
  30. std::size_t pos = 0;
  31. if ((pos = line[i].find(std::to_string(num))) != std::string::npos) {
  32. line[i].replace(pos, 1, numbers[num]);
  33. }
  34. }
  35. std::cout << i+1 << ". " << line[i] << std::endl;
  36. }
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0s 3480KB
stdin
I have 5 apples and 9 bananas.
Sam has 8 apples and 6 bananas.
stdout
1. I have five apples and nine bananas.
2. Sam has eight apples and six bananas.