Personally, I'd implement this as a Perl script because the hash type there makes it very easy.
Since it smells like a homework, here's a hint, but not a solution: look up the commands
last and
lastb. For example, to read the manual page for
last, use the command: