fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. // your code goes here
  5. int i, count;
  6. char prev,text[101] = {0};
  7.  
  8. scanf("%s",text);
  9.  
  10. prev = text[0];
  11. if(prev == NULL)
  12. {
  13. printf("0\n");
  14. }
  15. else
  16. {
  17. for(i = 0;text[i] != NULL;i++)
  18. {
  19. if(text[i] < 'a' || text[i] > 'z')
  20. return 0;
  21. }
  22. count = 1;
  23.  
  24. for(i = 1;text[i] != NULL;i++)
  25. {
  26. if(prev == text[i])
  27. {
  28. count++;
  29. }
  30. else
  31. {
  32. printf("%c", prev);
  33. if(count > 1)
  34. printf("%d",count);
  35. count = 1;
  36. prev = text[i];
  37. }
  38. }
  39. printf("%c", prev);
  40. if(count > 1)
  41. printf("%d",count);
  42. printf("\n");
  43. }
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 2296KB
stdin
aaaaaaaaaabbbbbbbbbbbbcccccccddddddddddeeeeeeefffffffffghiiiiiiiii
stdout
a10b12c7d10e7f9ghi9