fork download
  1. program elevatorbuttons;
  2. var
  3. hi, lo, pos, i : LongInt;
  4. ans, pressedButtons,Butt : AnsiString;
  5.  
  6. begin
  7. {
  8.   uncomment the two following lines if you want to read/write from files
  9.   assign(input, 'input.txt'); reset(input);
  10.   assign(output, 'output.txt'); rewrite(output);
  11. }
  12.  
  13. ReadLn(lo, hi, pos);
  14.  
  15. ReadLn(pressedButtons);
  16.  
  17. ans := '';
  18. for i:=1 to length(pressedButtons) do
  19. begin
  20. Butt:=copy(pressedButtons,i,1);
  21. case Butt of
  22. 'D' :pos:=pos-1;
  23. 'U' :pos:=pos+1;
  24. '0' :pos:=0;
  25. end;
  26. Butt:='';
  27. if (pos<lo) or (pos>hi) then begin ans:='error'; WriteLn(ans); exit;end;
  28. end;
  29. str(pos,ans);
  30. WriteLn(ans);
  31. end.
  32.  
Success #stdin #stdout 0.01s 5288KB
stdin
-1 7 3
UUDD0U


stdout
1