pls can i get a hint to solve this question.I dont want to see the solution before thinking and solving on my own.
Logic to solve the question
hi
the question is quite simple
it says that u are given a number an then u need to produce the minimum no
minimmum no can be produced if present digit can be reduced if 9-digit < presentdigit
do not change the digit if 9-digit is not less than presentDigit
Hint: consider input as string
#include #include<bits/stdc++.h> #define ll long long int using namespace std; int digits(int n) { int ctr=0; while(n>0) { ctr++; n/=10; } return ctr; } void pattern(int arr[],int d) { int c=-1; if(arr[0]!=9) { if(arr[0]>9-arr[0]) { arr[0]=9-arr[0]; } } for(int i=1;i<d;i++) { for(int j=i-1;j>=0;jā) { if(arr[j]!=0) c=1; } if(arr[i]>9-arr[i] && c==1) { arr[i]=9-arr[i]; } } for(int i=0;i<d;i++) { cout<<arr[i]; } cout<<endl; } int main() { ll n; cin>>n; int d=digits(n); int arr[20]; for(int i=d-1;i>=0;iā) { arr[i]=n%10; n=n/10; } pattern(arr,d); return 0; }
pls help me debug the above code.
int main() { string st; cin>>st; string s=st; char ch; string str=st; if(s[0]!=ā9ā) { if(s[0]-48>57-s[0]) { s[0]=57-s[0]; } } for(int i=1;i<s.length();i++) { ch=s[i]; if(ch-48>57-ch) { s[i]=57-s[i]; } } if(str.compare(s)<0) { cout<<s; } else cout<<str; return 0; }
i tried it using string too but the code is not working.
code with input as long long int has been debugged and running successfully.Pls help me with the logic involving string as input
Hey u cant expect me to debug ur code this way
u need to always use the cb ide while u need someone to debug the code