ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1135. Recruits

DO 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.
Posted by der_spider 2 Mar 2008 03:49
10
>>>><>>><

What about this test?
Re: Explanation here.
Posted by Pegasus 23 Nov 2012 11:06
thanks