fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. { int t;
  7. cin>>t;
  8. while(t--)
  9. {
  10.  
  11. string ciag;
  12. cin>>ciag;
  13. char z;
  14. int n=ciag.size();
  15. z=ciag[0];
  16.  
  17. int ile=1;
  18. for(int i=1;i<n;)
  19. {
  20. while(z==ciag[i])
  21. {
  22. ile++;
  23. i++;
  24. }
  25. if(ile>2)cout<<z<<ile--;
  26. else
  27. {
  28. while(ile--)cout<<z;
  29. }
  30. z=ciag[i];
  31. ile=0;
  32. }
  33. cout<<endl;
  34. }
  35.  
  36.  
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0s 15240KB
stdin
2
A
ZZZZZZIZZ
stdout
Z6IZZ