Here is the my solution for poj.org(peking university judge online)