ChewBacca and Number it's failing in third testcase please help

#include<bits/stdc++.h>
using namespace std;
int main() {
string s;
cin>>s;
int i=0;
while(i<s.length())
{
if(s[i]==‘9’)
i++;
else
break;
}
for(int j=i;j<s.length();j++)
{
int p=s[j]-‘0’;
int q=9-(s[j]-‘0’);
s[j]=min(p,q)+‘0’;
}
cout<<s;
}

@himanshulal30 hey himanshu take this senario
Input 99999
your output is 99999
but output is 90000.

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.