And have you tried to solve this or you just want to be handed the answer? No one will do your homework because:
1. Probably they can spend their time doing something else.
2. THIS WILL NOT HELP YOU AT ALL.
Programmers don't just appear after graduating a highschool or a university, but they do form in that period of time, learning and doing programming. If you want just the answer, you'll never learn anything.
I suggest you take this problem, analyze it on paper, than write a code that suits it. If then you have problems, and come with the part of the code that is giving you headaches, maybe we can help you, but first we need to see that you've tried.
Best luck to solving your problem.