optimize Word Search.cpp