Can I pls get why Am I getting TLE for all the test cases but I am getting one of the testcases correct?

Can I pls get why Am I getting TLE for all the test cases but I am getting one of the testcases correct? Can you help me figure out something where I did wrong?

@gvspraveen113 please share your code on cb ide

#include #include using namespace std; int main() { string s; getline(cin,s); for(int i=0;i<s.length();i++){ int cnt=1; while(s[i+1]==s[i]){ cnt+=1; continue; } cout<<s[i]<<cnt; } return 0; }

Sorry, How Can I share my code on CodingBlocks IDE?

@gvspraveen113
go to ide.codingblocks.com and paste your code there
click on file>save
a link will be generated, share that link here

https://ide.codingblocks.com/s/276683 Pls check the error in my code

@gvspraveen113

  1. instead of a while loop, just use a simple if statement. The looping will be done through for loop, so while is not required here
  2. cnt will be initialised as 1 for each iteration, so it will not retain its value even if you incremement it. Declare it outside the for loop and then change/print its value

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.