the code is running fine upto number 10^18 whats the problem in the code ?
code link :https://ide.codingblocks.com/s/100034
CHEWBACCA AND NUMBER two testcases showing no output
Read the question carefully u have to print the minimum not maximum and also the if condition is wrong
@phantom hi , i used 9-a[i] for a[i]>4 that means for 5,6,7,8 i want to print 4,3,2,1 , that seems okay and for the if a[i]==0 or a[i]==9 then it will invert it to 0 which we have to ignore acc to the prob , pls help i didnt get it .
in line 25 u have write
if(A[0]==9 || A[0]==0) {
return 0 ;
}
id ex=9562 then u r always returning 0 as A[0] is always 9
if a[0]0==9 then also ur code will not work as u have return if a[0]==9 || a[0]==0 return0;
cuz after inverting it will become 0 that is not acceptable
when u write return 0 that means u r terminating the program
The decimal representation of the final number shouldn’t start with a zero. if the first digit is 0 then close the program , thats what i hv done , pls help , iam not getting it …
u have also close the programe if a[0]==9
check for an exmaple starting with digit 9
can u pls modify my code … ?
check this
thanks , i hope this works for me
it is opening for me
did u get ur error point
yes , so basically i was returning 0 whr a[i]=9 but at that case 9 will be min possible no as we dont have any other possible solution , thanks , is there anything iam missing except that ???
no you got it
thank you so much !
#include<bits/stdc++.h>
using namespace std;
int main()
{
string num;
cin>>num;
for(int i=num.length()-1;i>=0;i--)
{ string temp=num;
char m=num[i];
char n='9';
if(m>4)
num[i]=n-num[i]+48;
if(num>temp)
num[i]=m;
}
cout<<num;
}
my two test cases are not running