siemka, napisałem kod wykonujący zadanie, który wydaje mi się poprawny. Dla przykładowego wejścia z przykładu otrzymuję poprawne wyjście. Niestety nie mogę doszukać się błędu.
Oto kod:
#include <iostream>
using namespace std;
string int_to_string(int liczba)
{
string zwracany;
if(liczba<10)
zwracany = char(liczba+48);
else if(liczba>=10 && liczba<100)
{
string pomocniczy;
zwracany = char(((liczba/10)%10)+48);
pomocniczy = char((liczba%10)+48);
zwracany += pomocniczy;
}
else
{
return "Jestesmy poza zakresem funkcji...";
}
return zwracany;
}
int main()
{
int testAmount;
cin>>testAmount;
string slowa[testAmount];
for(int i = 0 ; i<testAmount ; i++)
{
cin.clear();
cin.sync();
getline(cin,slowa[i]);
}
//65-90
for(int a = 0 ; a<testAmount ; a++)
{
for(int i = 65 ; i<91 ; i++)
{
size_t found = string::npos, found2 = string::npos;
int licznik = 0;
string pomoc;
pomoc = char(i);
found = slowa[a].find(pomoc);
if(found!=string::npos)
{
found2 = found;
licznik++;
while(found!=string::npos)
{
found = slowa[a].find(pomoc, found+1);
if(found!=string::npos) licznik++;
}
}
if(licznik>2)
{
slowa[a].erase(found2+1,licznik-1);
slowa[a].insert(found2+1,int_to_string(licznik));
}
}
cout<<slowa[a]<<endl;
}
return 0;
}