Tutaj mój kod. Nie wiem czemu nie działa. Jakieś wskazówki?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a;
int b, c = 1, j;
cin >> b;
for (int i = 0; i < b; i++)
{
cin >> a;
for (j = 1; j<a.length(); j++)
{
if (a[j - 1] == a[j])
{
c++;
if (j ==(a.length() - 1))
{
if (c == 2) cout << a[j - 1] << a[j - 1];
else if (c != 2) cout << a[j - 1] << c;
c = 1;
}
}
else
{
if (c == 1) cout << a[j - 1];
else if (c == 2) cout << a[j-1] << a[j-1];
else if (c != 2) cout << a[j - 1]<<c;
if (j ==(a.length() - 1)) cout << a[j];
c = 1;
}
}
cout<<endl;
}
return 0;
}