My UVA Solution in C++