Complete solution for function rankhospital()