Finish all test cases & fixed bugs about greedy matching

Finish all test cases & fixed bugs about greedy matching