Problem - String Comprehension (interview prep in c++)
code -
#include
#include
using namespace std;
int main() {
string str,res;
int cnt=0;
cin>>str;
char ch = str[0];
for(auto c : str){
if(c == ch)cnt++;
else{
res.push_back(ch);
res+=to_string(cnt);
ch = c;
cnt =1;
}
}
cout<<res;
return 0;
}