I have tried several inputs but i’m not able to get the testcase which is failed by the code. Please help me in guiding me which testcase shoud i need to consider in order to make the code fully working.
String Compression
hi @mvermav19
try this -->
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
if(s.length()==1){
cout<<s<<"1";
return 0;
}
for(int i=0;i<s.length();i++){
int count=1;
for(int j=i+1;j<s.length();j++){
if(s[i]==s[j])
{
count++;
}
else{
break;
}
}
cout<<s[i]<<count;
i=i+count-1;
}
return 0;
}
hi @mvermav19
It’s some compiler issue that’s why the code is failing on some test cases… earlier it passed all… so don’t worry u can move ahead with other questions…
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.