String Compression

//can anyone please tell i am getting wrong answer on test case 1 and 2

[https://ide.codingblocks.com/s/289620](https://ide.codingblocks.com/s/289620)
#include<iostream>

#include<string>

using namespace std;

void compress(string s,int n)

{

    int i=0,count=1;

    while(i<n)

    {

        count=1;

        while(s[i]==s[i+1])

        {

            count++;

            i++;

        }

        cout<<s[i]<<count;

        i++;

    }

}

int main() 

{

    string s;

    cin>>s;

    compress(s,s.length());

    return 0;

}

I think you got the question wrong!!
Hope it helps!!

1 Like