0
I don't know how to solve this problem."n" numbers are given.These must be displayed in ascending order after the last digits.
"n" numbers are given.These numbers must be displayed in ascending order after the last digit of the number. I tried to solve this,but i can't finish it. Can you help me? C++ https://code.sololearn.com/cR2IU8LfzgvL/?ref=app
9 odpowiedzi
+ 4
for(i=0;i<n-1;i++){
for(j=i+1;j<n;j++{
m=arr[i],n=arr[j]
for(int k=1;k<=(max_lengthBetween(arr[i],arr[j]));k++){
/*
compare last digit of m,n using %10 &
change value of m,n by /10 (removing their last digit),
if last digit of m is less than last digit of n,
then replace value of arr[i] & arr[j] and break;
from this inner loop
*/
}
}
}
//purpose of max_lengthBetween(arr[i], arr [j]) is to handle elements with different lengths like 234, 1234 here 1234>0234 as 1>0
+ 2
Input:
3 - that means that only 3 numbers are allowed to be used, but i can write 6,12 if i want.
2313
241
712-these are the numbers.
Output:
Because the last digit of 2313 is the hightest, it will be displayed first.
After- 712 and then 241
So the output will be diaplayed like that:
2313
712
241
+ 2
till line 13th program seems to be correct(taking input correctly), after that it looks like you are trying to use selection sort so you need 2 loops for it, but inside that inner loop you need another loop for comparing last digits(like in 243 & 253, we can't sort by just looking at 3, we need to look next last digit 4,5 also) and using it swap values in array.
+ 1
George Listru
Can you give an example of what input is given and what output is expected?
Is this related with the previous problem? I thought you already solved it.
+ 1
I do not understand very well because I do not speak native English. Can you show me in the program?
+ 1
George Listru
Making a progress? it's pretty quiet here.
Just came to confirm something. So the number of digits in each input number doesn't matter, we just sort them by their last digit in descending order. Is this really how it is supposed to work? but what if one of the numbers were negative? what then?
For example, 4 samples:
542, 713, 420, -821
Should the output be like this:
713
542
420
-821
0
I got a lot of errors, can you insert this in my program so i can see better?