fork download
  1. #include <iostream>
  2. #include <ctype.h>
  3.  
  4.  
  5. int get_l10(int n){
  6. if(n < 10)
  7. n = 1;
  8. else if(n < 100)
  9. n = 2;
  10. else if(n < 1000)
  11. n = 3;
  12. return n;
  13. }
  14.  
  15.  
  16. char* s_rep_len(char* s){
  17. char* p1, *p2, *p3, *p4, ch;
  18. int i, n = 0;
  19.  
  20. p1 = p2 = p3 = s;
  21.  
  22. do {
  23. ch = *p1 = *p2;
  24.  
  25. if(! isalpha(*p1)){
  26.  
  27. if(n > 0){
  28.  
  29. i = get_l10(n);
  30. p4 = p3 + (i - 1);
  31. while(n != 0){
  32. *p4-- = (char)(n % 10) + '0';
  33. n /= 10;
  34. }
  35.  
  36. p3 += i;
  37. p1 += i + 1;
  38. *p3++ = ' ';
  39. n = 0;
  40. }
  41.  
  42. ++p1;
  43. } else
  44. ++n;
  45. ++p2;
  46.  
  47. } while(ch != '\0');
  48.  
  49. *p3 = '\0';
  50. return s;
  51. }
  52.  
  53.  
  54. int main(void){
  55. char s[] = "An example of a string of characters";
  56. std::cout << s_rep_len(s) << std::endl;
  57. return 0;
  58. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
2 7 2 1 6 2 10