0

Delete the greater number from a big number using just while loop

Input 5912 Output 512

24th Feb 2021, 5:16 PM
Andrei Macovei
Andrei Macovei - avatar
11 RĂ©ponses
+ 2
What if it takes more than 1 while-loop? does it have to be done with 1 while-loop? What if there are multiple greatest digit? e.g. 2021 (digit 2 appear twice) And what if all the digits are the same? e.g. 999
24th Feb 2021, 6:36 PM
Ipang
+ 2
I tried, but I couldn't get it to work as expected if I must strictly use only 1 while-loop ...
24th Feb 2021, 6:41 PM
Ipang
+ 1
Ipang agree with you but any idea?
24th Feb 2021, 6:39 PM
Andrei Macovei
Andrei Macovei - avatar
+ 1
Ipang pang try with multiple while loop
24th Feb 2021, 6:42 PM
Andrei Macovei
Andrei Macovei - avatar
+ 1
My confirmation remains unanswered ... what if there are multiple greatest digit? and what if all digits are the same?
24th Feb 2021, 6:46 PM
Ipang
+ 1
Here it uses 2 while loop. First one searches for largest digit, and second one builds the resulting number. https://code.sololearn.com/ckC9l6ULuP9N/?ref=app
24th Feb 2021, 7:35 PM
Ipang
0
#include <iostream> using namespace std; int main() { int N,uc,c,y=0,p=1; cin>>N; ; while(N!=0){ uc=N%10; if(max(uc,9)) c=uc*0; N=N/10; if(N%10!=0){ y=(N%10)*p+y; p=p*10; } } cout << y; return 0; }
24th Feb 2021, 5:17 PM
Andrei Macovei
Andrei Macovei - avatar
0
this I try
24th Feb 2021, 5:18 PM
Andrei Macovei
Andrei Macovei - avatar
0
Mirielle[ INACTIVE ] the program should see all numbers from that number and delete the biggest one
24th Feb 2021, 6:32 PM
Andrei Macovei
Andrei Macovei - avatar
0
You have numbers till 9 so if you have a number like 9987 output will be 87
24th Feb 2021, 6:49 PM
Andrei Macovei
Andrei Macovei - avatar
0
But is not specify the particulars cases
24th Feb 2021, 6:50 PM
Andrei Macovei
Andrei Macovei - avatar