I wrote the code for the problem CodeChef: Practical coding for everyone
I cant seem to understand why I am getting an error. Please help me. My code is as follows:-
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
int n=s.length();
bool flag=false;
if(n==1)
{
cout<<s<<endl;
continue;
}
if(s[0]=='1')
{
flag=true;
}
else if(s[1]!='9')
{
s[0]=s[0]-1;
}
for(int i=1;i<n;i++)
{
if(flag==false)
{
s[i]='9';
}
else
{
if(s[i]!='0'&&i!=n-1&&s[i+1]!='9')
{
s[i]=s[i]-1;
flag=false;
}
}
}
cout<<s<<endl;
}
}