|
|
back to boardDO LIKE ME Accepted HE MY PROGRAM memory 17 byte Posted by Oleg 4 Nov 2002 19:30 var i,n,L,R:longint; ch:char; begin readln(n); L:=0; R:=0; for i:=1 to n do begin read(ch); while not(ch in ['<','>']) do read(ch); case ch of '>':inc(R); '<':inc(L,R); end; end; writeln(L); end. Could you give me an explanation? I couldn't understand your program. Posted by af 18 Nov 2002 10:37 Explanation here. Denote by R the number of recruits at the right end of the queue. When you get a new '>', simply increase R by 1. If you receive a '<', the process is like this: >>>>>< (Say R=5) >>>><> >>><>> >><>>> ><>>>> <>>>>> Now you see, it takes exactly R turns to send the '<' to the left of the '>'s, and the number of the '>'s, or R, stays the same. So it's easy to understand the prog. Re: Explanation here. 10 >>>><>>>< What about this test? Re: Explanation here. Posted by Pegasus 23 Nov 2012 11:06 thanks |
|
|