fork download
  1. #include <iostream>
  2. using namespace std;
  3. /*
  4. string int_to_string(int liczba)
  5. {
  6.   string zwracany;
  7.   if(liczba<10)
  8.   zwracany = char(liczba+48);
  9.   else if(liczba>=10 && liczba<100)
  10.   {
  11.   string pomocniczy;
  12.   zwracany = char(((liczba/10)%10)+48);
  13.   pomocniczy = char((liczba%10)+48);
  14.   zwracany += pomocniczy;
  15.   }
  16.   else if(liczba>=100 && liczba<1000)
  17.   {
  18.   string pomocniczy, pomocniczy2;
  19.   zwracany = char(((liczba/100)%10)+48);
  20.   pomocniczy2 = char(((liczba/10)%10)+48);
  21.   pomocniczy = char((liczba%10)+48);
  22.   zwracany = zwracany + pomocniczy2 + pomocniczy;
  23.   }
  24.   else
  25.   {
  26.   return "Jestesmy poza zakresem funkcji...";
  27.   }
  28.   return zwracany;
  29. }
  30. */
  31. int main()
  32. {
  33. int testAmount;
  34. cin>>testAmount;
  35. string slowa[testAmount];
  36. for(int a = 0 ; a<testAmount ; a++)
  37. {
  38. //cin.clear();
  39. //cin.sync();
  40. cin>>slowa[a];
  41.  
  42. size_t found = string::npos, found2 = string::npos, found3 = string::npos;
  43. int licznik;
  44. for(int i = 65 ; i<91 ; i++)
  45. {
  46. found = string::npos; found2 = string::npos; found3 = string::npos;
  47. licznik = 0;
  48. found = slowa[a].find(char(i));
  49. if(found!=string::npos)
  50. {
  51. found2 = found;
  52. licznik++;
  53. while(found!=string::npos)
  54. {
  55. found3 = found;
  56. found = slowa[a].find(char(i), found+1);
  57. if(found!=string::npos && found3==(found-1))
  58. {
  59. licznik++;
  60. }
  61. else
  62. {
  63. if(licznik>2)
  64. {
  65. slowa[a].erase(found2+1,licznik-1);
  66. slowa[a].insert(found2+1,to_string(licznik));
  67. }
  68. licznik = 0;
  69. found2 = slowa[a].find(char(i), found2+2);
  70. if(found2!=string::npos) {licznik++; found = found2;}
  71. }
  72. }
  73. }
  74. }
  75. }
  76.  
  77.  
  78. for(int i = 0 ; i<testAmount ; i++)
  79. cout<<slowa[i]<<endl;
  80.  
  81. return 0;
  82. }
Success #stdin #stdout 0s 3476KB
stdin
1
HDHDHHHH
stdout
HDHDH4