Form biggest Numbers

Can I know that how to arrange two number and store in a variable like a =10, b =23, and result will be 1023, 2310.
I want to store in the third result varible…

u could convert each no to its string representation using to_string()

store each no as string temp1 , temp2
u can achieve 1023 by temp1+temp2
ans 2310 by temp2+ temp1

@chhavibansal thanks Got it

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Hi @Vikaspal
Is your doubt clear ? If it is clear then mark your doubt as resolved.

sure @Aayush i will closed it

#include
#include
using namespace std;

int main() {

int a=343;
int b =4343;
string temp1 = to_string(a);
string temp2 = to_string(b);

string str = temp1 + temp2;
cout << str;

return 0;

}

I thought try to convert the int to string and make the concentation of all possible combination of and then convert back to integer to check if the number is greater or not but the thing when i generate the subarrays I need to create the varible for all the n length subarrays to convert that into string .
Could you suggest me something.

hi bro , u are somewhere in the right direction, u just need to compare the two string formed and return the smaller one
a customised sort function would work well for us

in the simple sort function, we call a customised function where we form combination of a+b and b+a and return the answer in increasing order
Please have a look at the code lexicographically


I made little change but didn’t work and also could explain the new format of for loop which is given in main () function

the code is getting into a infinite loop since u have written
while(c < 2) and u are not incrementing c any where
u need to add c++ at the end and add 2 test cases

this is for each loop
When we do not need to access the indexes but need just the values, we simply can use the foreach loop
read about for-each loop in c++
i`ll tell u the general format
for( datatype variable_name : array_name_for_which_iteration_is_done){
cout << variable_name <<" " ;
}

so soory brother, I did a that mistake that I think didn’t supposed to that :slightly_smiling_face:

it happens its fine.

1 Like

Can u little explain me the cmp internallly. It each each stage?

randomized quick sort is implemented in the cmp function, u can watch prateek bhaiyas video covering the same