String compression

Please explain where I’m going wrong with this code:
#include
#include
using namespace std;

int main()
{
string s;
cin>>s;
int n = s.length();
int a[26] = {0};
for(int i=0; i<n; i++)
{
int diff = s[i]-97;
a[diff]++;
}
for(int i=0; i<n; i++)
{
if(a[i]>0)
{
cout<<char(i+97)<<a[i];
}
}
return 0;
}

hello @shreyasdaga
u have misunderstood the problem.
here u only have to compress consecutive same character.
for example->
aaabbaac
then output should be
a3b2a2c1

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.