#include
#include
using namespace std;
void compress(char a[])
{
int cnt=-1;
int freq[26]={0};
for(int i=0; a[i] != ‘\0’; i++)
{
char ch=a[i];
freq[ch-‘a’]++;
}
for(int i=0; a[i] != ‘\0’ {
i=i+freq[a[i] - ‘a’];
char ch=a[i-1];
cout<<ch;
if(freq[ch-‘a’]>1)
cout<<freq[ch-‘a’];
}
}
int main()
{
char a[100];
cin.getline(a, 100);
compress(a);
}
Here is my code
My one testcase is not getting passed but the input and output of the failed testacse is same as that given in question
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.