whats wrong in my code for frieza

#include
#include<string.h>
using namespace std;

int main()
{

int t;
cin>>t;

while(t>0)
{

string s="";

cin>>s;

int ans=0;
int c;

string s2=“frieza”;

for(int i=0;s[i]!=’\0’:wink:
{

c=0;

 if(s[i]=='f'||s[i]=='r'||s[i]=='i'||s[i]=='e'||s[i]=='z'||s[i]=='a')
  {
     while(s[i]=='f'||s[i]=='r'||s[i]=='i'||s[i]=='e'||s[i]=='z'||s[i]=='a'&&s[i]!='\0')
      {
      c++;
      i++;

      }
      ans=(ans*10)+c;
  }
  else
    {
    while(s[i]!='f'&&s[i]!='r'&&s[i]!='i'&&s[i]!='e'&&s[i]!='z'&&s[i]!='a'&&s[i]!='\0')
      {
      c++;
      i++;

      }
      ans=(ans*10)+c;
    }

}
string a=to_string(ans); cout<<a<<endl;
t–;
}

return 0;
}

Instead of making
ans=(ans*10)+c
directly do
cout <<c;.
And before each test case ends

cout<<endl;

As you can see in testcases that output answer is can be big string of integers, therefore the integer ans in which you are storing it can overflow, and will mostly overflow.

Instead of posting your code… Post soln link… it ll help more… as code don’t look clearer sometimes on discuss

As there can be 10^5 digits so It will exceed “long long int” also…

So your answer eventually will go out of range of integers

#HERE is a neat accepted solution…

Thanks i got it now i will make sure i wont repeat this mistake again…

1 Like

welcome :slight_smile:
If you found a correct answer on your question then just click on that tick on that answer…
It is called accepting a answer…