fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. int ile;
  8. string napis;
  9.  
  10.  
  11. int main()
  12. {
  13. cin>>ile;
  14. for(int d=0;ile>d;d++)
  15. {
  16. int e;
  17. int x=-1;
  18. int y=-1;
  19. int l;
  20.  
  21. cin>>napis;
  22.  
  23. do
  24. {
  25. x++;
  26. y++;
  27. e=x;
  28. l=y;
  29. }
  30. while(x!=0);
  31.  
  32.  
  33. while(e<napis.length())
  34. {
  35. if(napis[e]!=napis[e+1])
  36. {
  37. cout<<napis[e];
  38. e+=1;
  39. }
  40. else if (napis[e]==napis[e+1]&&napis[e]!=napis[e+2])
  41. {
  42. cout<<napis[e]<<napis[e+1];
  43. e+=2;
  44. }
  45. else if(napis[e]==napis[e+1])
  46. {
  47. while(napis[e]==napis[e+1])
  48. {
  49. e++;
  50. }
  51. cout<<napis[e]<<e+1-l;
  52. e+=1;
  53. }
  54. l=e;
  55. }
  56.  
  57. cout<<endl;
  58.  
  59.  
  60. }
  61. return(0);
  62. }
  63.  
Success #stdin #stdout 0s 15232KB
stdin
4
OPSS
ABCDEF
ABBCCCDDDDEEEEEFGGHIIJKKKL
AAAAAAAAAABBBBBBBBBBBBBBBB
stdout
OPSS
ABCDEF
ABBC3D4E5FGGHIIJK3L
A10B16