fork download
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. char s[4000], aux[4000];
  8. int k = -1, nr;
  9. cin.getline(s, 2000, 0);
  10. int lg = strlen(s);
  11. for (int a = 0; a < lg; ++a){
  12. if (isalpha(s[a])){
  13. nr = 1;
  14. if (s[a] == s[a + 1]){
  15. do {
  16. ++nr;
  17. ++a;
  18. }
  19. while(s[a] == s[a + 1]);
  20. }
  21. ++k;
  22. aux[k] = '0' + nr;
  23. ++k;
  24. aux[k] = s[a];
  25. }
  26. else {
  27. ++k;
  28. aux[k] = s[a];
  29. }
  30. }
  31. strcpy(s, aux);
  32. cout << s;
  33. return 0;
  34. }
Success #stdin #stdout 0s 5304KB
stdin
jagger sold the cannnnon??
stdout
1j1a2g1e1r 1s1o1l1d 1t1h1e 1c1a4n1o1n??