Hi, if ( commnad sequence is bad ) whether to include it area calculation or not??
On 10/5/07, piruk <[EMAIL PROTECTED]> wrote: > > > Hi. > How to solve this task? > > > Areameter is a turtle-like self-propelled vehicle controlled by > sequences of commands transmitted over a radio channel. Initially the > vehicle is oriented in some fixed direction, let's say to the North. > Commands instruct Areameter how far to move in the current direction > and where to turn after the move. Allowed turns are +90 or -90 degrees > relative to the current direction. By positive turn we mean turning to > the right (clockwise). > > A command sequence is good if it brings the vehicle to the starting > point and starting orientation after tracing a closed non self- > intersecting path. On coming back to the starting point Areameter > should emits the area (number of square units) of the territory walked > around. > > Write a program to perform Areameter's task of calculating the area > from the sequence of received commands. > > Input > > The standard input stream contains a sequence of test cases specified > as follows: > > The first line contains a positive integer n, number of test cases. > A test case is simply one good command sequence spread over one or > more lines. Each command sequence consists of alternating move and > turn commands. Move command is represented by a positive integer; turn > command is represented by single character '+' or '-'. End of command > sequence is coded by giving 0 for move command. Commands are separated > by at least one white-space character. You can assume the input is > well-formed and contains only good command sequences. There are no a > priori constraints on the sequence length. The values of moves and the > resulting area are all within integer representation. > > Output > > For each test case the program should output one text line containing > a number: the area in square units. > > Example > Input > 3 > 3 + 3 + 3 + 3 + 0 > > 2 + 2 + 3 - 3 - 1 + 2 + 3 + 3 + > 1 - 3 + 2 - 1 + 0 > > 2 + 2 - 1 - 1 + 1 + 3 + 3 + 2 - 2 - > 4 - 4 + 2 + 2 + 1 - 1 - 2 + > 1 + 1 - 1 + 7 + 2 - 1 + 0 > > Output > 9 > 16 > 27 > > > > > -- PRADEEP MACHARLA Ph:08040141194 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/algogeeks -~----------~----~----~----~------~----~------~--~---