Help with approach

prob: https://hack.codingblocks.com/app/contests/2022/508/problem
sol: https://ide.codingblocks.com/s/397346

I’m storing the numbers upto in a string and then I’m planning to sort it, but the code I have written so far(storing in the string) isn’t working please check.

Hey @raghav007
You are trying to add integer to string which is wrong
2nd thing if u want to sort then u must use array/ vector of strings

	string v[n+1];
	for(int i=0;i<=n;i++){
        v[i]=to_string(i);
    }

this will store all the numbers as string in array

correct… I tried converting it this way int + ‘0’ and it worked could you please explain the logic behind this. I guess it has something to do with typecasting

will only work with digits because of ascii value
but will not work with nums>=10

for that u have to use to_string() function
u can create one ursefl
take modul of number and add it to string

strin num="";
int n;
cin>>n;
while(n!=0){
     num=(n%10+'0') + num;
     n=n/10;
}
return num;


please check this approach. I have tried to convert int to string

one mistake which I made here is I have taken the input for an array (confused this with other some question)

Hey


the array is being sorted properly but the elements are not being printed from 0

Hey https://ide.codingblocks.com/s/397421

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.