fork(4) download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main(){
  6. int C, count = 1;
  7. string S;
  8. string wynik;
  9. cin >> C;
  10. ++C;
  11. while (--C) {
  12. cin >> S;
  13. wynik = "";
  14. count = 1;
  15. //cout << S[0];
  16. wynik += S[0];
  17. for (int i = 1; i <= S.size(); i++) {
  18. if (S[i] != S[i - 1]) {
  19. if (count > 2) {
  20. //cout << count;
  21. wynik += to_string(count);
  22. }
  23. else if (count == 2) {
  24. //cout << S[i - 1];
  25. wynik += S[i - 1];
  26. }
  27. //cout << S[i];
  28. wynik += S[i];
  29. count = 1;
  30. }
  31. else {
  32. ++count;
  33. }
  34. }
  35. if (C != 1) {
  36. //cout << endl;
  37. wynik += '\n';
  38. }
  39. cout << wynik;
  40. }
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5548KB
stdin
4
OPSS
ABCDEF
ABBCCCDDDDEEEEEFGGHIIJKKKL
AAAAAAAAAABBBBBBBBBBBBBBBB
stdout
OPSS
ABCDEF
ABBC3D4E5FGGHIIJK3L
A10B16