fork(1) download
  1. #include <iostream>
  2. #include <cstdio>
  3.  
  4. using namespace std;
  5.  
  6. int ile;
  7. string l;
  8.  
  9. int main()
  10. {
  11. cin >> ile;
  12. for (int i=0; i<ile; i++)
  13. {
  14. cin >> l;
  15. for (int i=0; i<l.length(); i++)
  16. {
  17. int s=0;
  18. if(l[i+1]==l[i] && l[i+2]==l[i])
  19. {
  20. for (int j=i+1; j<l.length(); j++)
  21. {
  22. if(l[j]==l[i+1])
  23. {
  24. s++;
  25. }
  26. }
  27. }
  28. if (s>1)
  29. {
  30. string x; sprintf((char*)x.c_str(), "%d", s+1);
  31. string y=x.c_str();
  32. if (s<9)
  33. {
  34. l.replace(i+1,1,y);
  35. l.erase(i+2,s-1);
  36. }
  37. else if (s>=9 && s<99)
  38. {
  39. l.replace(i+1,2,y);
  40. l.erase(i+3,s-2);
  41. }
  42. else
  43. {
  44. l.replace(i+1,3,y);
  45. l.erase(i+4,s-3);
  46. }
  47. }
  48. }
  49. cout<<l<<endl;
  50. }
  51. return 0;
  52. }
Success #stdin #stdout 0s 3476KB
stdin
4
OPSS
ABCDEF
ABBCCCDDDDEEEEEFGGHIIJKKKL
AAAAAAAAAABBBBBBBBBBBBBBBB
stdout
OPSS
ABCDEF
ABBC3D4E5FGGHIIJK3L
A10B16