Final Version

So many bugs……exhausted.
Function is still simple but can solve the problem in homework#2