code of Google code jam problem(C++)