How to get output in given format

i managed to get the ans in sorted order but i cant able to print in the output format please check my code i have written it but how can i stop it from putting comma at the last position.
code- https://ide.codingblocks.com/s/270893

@anubhavb11 iterate till size-1 to display comma and cout the last value directly after that

but i am using for each loop and i dont know how to itrate over inbuilt hashmap using for loop

@anubhavb11
auto start=map.begin();
auto end=map.end();
end–;
for(auto it=start;it<end;it++)
try something like this

there is a problem in it you cant figure out if the end-1 element is going to print or not

@anubhavb11 if ans is atleast 1 no then it is going to work


i tried it but it is giving this error

@anubhavb11 sry try p!=end

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.