Output shows only first digits of output

I am not able to identify my mistake could you please help?

I have commented the possible errors in your code.

for(int j=n;j>=1;j--){
    best_pos=n-j;
    init_pos=h[j]; // Why are you assigning value to position? 
    if(swap<k){
        if(init_pos!=best_pos){ 
           h[j]=best_pos; // Why are you assigning index to value?
           for(auto p:h){
               if(p.second==best_pos){ //Why are you comparing value to index?
                   p.second=init_pos; // Why are you assigning index to value?
                   swap++;

               }
           }
        }
    }
}

Please, resolve them.
if you still have doubts, feel free to ask.

I am marking this doubt as resolved as you have not replied to this thread for five days.
In case, you still have some doubts regarding the same problem then you can reopen this doubt.

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.