in reply to print identical keys once along with their values
You might want to take kennethk's last bit of advice first. Work out the mechanism first by hand. That will inform your choice of control structure and data structure.