fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4.  
  5. using namespace std;
  6.  
  7. int ile,dg,licznik=1;
  8.  
  9.  
  10.  
  11. string konwenter (int c)
  12. {
  13. ostringstream ss;
  14. ss << licznik;
  15. string str = ss.str();
  16. return str;
  17.  
  18. }
  19.  
  20. int main()
  21. {
  22. cin>>ile;
  23.  
  24. string napis[ile],koncowy[ile],z,x;
  25.  
  26. for (int i=0; i<ile; i++)
  27. {
  28. cin>>napis[i];
  29. dg=napis[i].length();
  30. licznik=1;
  31. for (int j=0; j<=dg; j++)
  32. {
  33. z=napis[i][j];
  34. x=napis[i][j+1];
  35. if(x==z) licznik++;
  36. else if ((x!=z)&&(licznik>2))
  37. {
  38. koncowy[i]+=z;
  39. koncowy[i]+=konwenter(licznik);
  40. licznik=1;
  41.  
  42.  
  43.  
  44. }
  45.  
  46. else if ((x!=z)&&(licznik==2))
  47. {
  48. koncowy[i]+=z;
  49. koncowy[i]+=z;
  50. licznik=1;
  51. }
  52. else if ((x!=z)&&(licznik==1)) koncowy[i]+=z;
  53. }
  54. cout<<koncowy[i]<<endl;
  55. }
  56. return 0;
  57. }
  58.  
Success #stdin #stdout 0s 3476KB
stdin
4
OPSS
ABCDEF
ABBCCCDDDDEEEEEFGGHIIJKKKL
AAAAAAAAAABBBBBBBBBBBBBBBB
stdout
OPSS
ABCDEF
ABBC3D4E5FGGHIIJK3L
A10B16