Preview:
#include <bits/stdc++.h> 
string encode(string &message)
{
    string ans="";
    int count=1;
    int n=message.size();
    for(int i=0 ; i<n ; i++)
    {
        if(message[i]==message[i+1])
        {
           count++;  
        }
         ans+=message[i];
    ans+=to_string(count);
    count=1;
    }
   
    return ans;
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter