fork download
  1. #include <iostream>
  2. #include <cctype>
  3. #include <string>
  4. #include <sstream>
  5. using namespace std;
  6.  
  7. bool isdigit(char c) {
  8. if(c>='0' && c<='9')
  9. return true;
  10. else
  11. return false;
  12. }
  13.  
  14. int main () {
  15. string str, num = "";
  16. getline(cin, str);
  17. char ultima_letra = 0;
  18.  
  19. for (size_t i=0; i < str.length(); ++i) {
  20. if (isdigit(str[i])) {
  21. num += str[i];
  22. } else {
  23. if (num.length() > 0 && str[i] != '.' && ultima_letra != '.' && ultima_letra !='-'){
  24. cout << "+";
  25. }
  26. ultima_letra = str[i];
  27. cout << num << str[i];
  28. num = "";
  29. }
  30. }
  31. if (num.length() > 0 && ultima_letra != '.' && ultima_letra !='-'){
  32. cout << "+";
  33. }
  34. cout << num << endl;
  35.  
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 4440KB
stdin
a1b12c3.14-20
stdout
a+1b+12c3.14-20