#K12951. Robotic Arm Simulation
Robotic Arm Simulation
Robotic Arm Simulation
The robotic arm performs a series of actions based on an input sequence consisting of the characters L
, R
, and P
. The L
command moves the arm one unit to the left, the R
command moves it one unit to the right, and the P
command represents picking up an item. Your task is to simulate these actions and calculate the final position of the arm as well as the total number of items picked up.
Formally, let \(p\) be the initial position (which is 0) and \(c\) be the count of items picked (initially 0). For each action in the input sequence:
- If the action is \(L\), update \(p = p - 1\).
- If the action is \(R\), update \(p = p + 1\).
- If the action is \(P\), update \(c = c + 1\).
The final output should display the final position \(p\) and the count \(c\) as two space-separated integers.
inputFormat
The input consists of a single line, which is a string representing the sequence of actions. Each character in the string is one of the following:
L
: Move the arm left.R
: Move the arm right.P
: Pick an item.
outputFormat
The output consists of two space-separated integers on a single line. The first integer is the final position of the arm and the second integer is the total number of items picked.
## sampleRLRPPPLR
1 3