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

Show all messages Hide all messages

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.
Explanation here. Maigo Akisame (maigoakisame@yahoo.com.cn) 5 Aug 2004 09:58
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. der_spider 2 Mar 2008 03:49
10
>>>><>>><

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