poj1978. try use list here. list would beat memmove/memcpy for large data set