Take as input S, a string. Write a function that does basic string compression. Print the value returned. E.g. for input “aaabbccds” print out a3b2c2d1s1

#include
#include<bits/stdc++.h>
#include
using namespace std;

int main()
{ string s1;

getline(cin,s1);
int h;
int count=1;
sort(s1.begin(),s1.end());
string s2=“0”;
s1.insert(s1.size(),s2);
for(int i=0;i<s1.size()-1;i++)
{
if(s1[i]==s1[i+1])
count++;
else
{ cout<<s1[i]<<count;
count=1;
}
}

return 0;

}

1-getting error in one output cases while submission.
2-want to know any other best way to do this.only hint not whlole code

Hello @SOHAN,

The way you have shared your code has introduced many syntax errors to it.
Please, share your code using Online Coding Blocks IDE.
STEPS:

  1. Paste the code at https://ide.codingblocks.com
  2. Save it there.
  3. Share the URL generated.

Possible mistakes:

  1. sort(s1.begin(),s1.end()); sorting will produce wrong output for the case:
    1.1. aabccaaa
    Expected Output:
    a2b1c2a3
    Your Output:
    a5b1c2
    1.2. aacccb
    Expected Output:
    a2c3b1
    Your Output:
    a2b1c3

192923 string compression C++ 18 Mar 2020 02:21:51 18 Mar 2020 02:22:04 my code for this problem

Hello @SOHAN,

How should i access that?
What is the URL?

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.