When reading the input, like this:
char *Input;
cin.getline(...);
the chars with ASCII code larger than 127 will become negative integers, for example, if the ASCII code is SUPPOSED to be 160, it will turn out to be 160-128.
Fix this trick, and you will get AC.
One more, this article will help you VERY MUCH if you don't really understand the problem statements.
http://acm.timus.ru/forum/thread.aspx?space=1&num=1177&id=10577&upd=632900666745579610 (It can be found just on the BOARD.)
GOOD LUCK~