fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <string.h>
  4. using namespace std;
  5. int main()
  6. {
  7. int n, length, count=0, to_count;
  8. string word;
  9. cin >> n;
  10. for (int i = 1; i <= n; i++) {
  11. cin >> word;
  12. length = word.length();
  13. for (int j = 0; j < length - 1; j++) {
  14. to_count = j - count;
  15. if (length > j) {
  16. if (word[j] != word[j + 1]) continue;
  17. else {
  18. count = 0;
  19. while (word[to_count] == word[to_count + 1]) {
  20. to_count++;
  21. count++;
  22. }
  23. if (count > 1) {
  24. word.replace(j + 1, count, to_string(count+1));
  25. length = word.length();
  26. }
  27. j = to_count - 1;
  28. }
  29. }
  30. }
  31. cout<<word<<endl;
  32. }
  33. }
Success #stdin #stdout 0.01s 5544KB
stdin
4
OPSS
ABCDEF
ABBCCCDDDDEEEEEFGGHIIJKKKL
AAAAAAAAAABBBBBBBBBBBBBBBB
stdout
OPSS
ABCDEF
ABBC3D4E5FGGHIIJK3L
A10B16