No.8126 Brainfxxk easy
Problem Statement
Brainfxxk (xx=uc) is $1$ of the esoteric programming languages. This language consists of $8$ kinds of instructions: +, -, >,
<, ., ,, [, ].
Yu-ti has decided to reproduce, out of the $8$ kinds of instructions, the $4$ kinds of instructions +, -, >,
<.
The behavior of each instruction is as follows.
-
+: Adds $1$ to the value of the data at the pointer's number (adds $1$ to the value of the data the pointer points to) -
-: Subtracts $1$ from the value of the data at the pointer's number (subtracts $1$ from the value of the data the pointer points to) -
>: Adds $1$ to the pointer's number (moves the pointer forward by $1$) -
<: Subtracts $1$ from the pointer's number (moves the pointer backward by $1$)
The data and their values are defined as follows.
- $N$ pieces of data are placed in $1$ row, and the pieces of data are numbered $1$, $2$,$ \cdots$, $N$ from the front.
- The value of each piece of data is initially $0$.
- The pointer's number is initially $1$.
Given the number of pieces of data and the code string, output the value of each piece of data after executing the code.
However, if the pointer takes the number of a nonexistent piece of data even $1$ time during execution, output
error.
Constraints
- $1 \leq N \leq 10 $
- $1 \leq |S|\leq 100$
- The string $S$ consists of
+,-,>,<.
Input
$N$
$S$
Line $1$ contains $N$, the number of pieces of data.
Line $2$ contains $S$, the code string.
Output
If the pointer takes the number of a nonexistent piece of data even $1$ time, output error.
Otherwise, output the value of each piece of data separated by spaces on $1$ line.
Print a newline at the end.
Sample
Sample 1
Input
3 +++>--
Output
3 -2 0
The pointer adds to the data number $1$ it points to $3$ times, the pointer moves backward by $1$, and the pointer subtracts from the 2nd piece of data it points to $2$ times.
Sample 2
Input
3 <>>>>
Output
error
The pointer moves forward by $1$ and points to a nonexistent piece of data, so error is output.
Even if the error at character $1$ is ignored, the pointer then moves backward by $4$ and points to a nonexistent piece of data.
Sample 3
Input
1 +-+-+-+-+-
Output
0
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
UT0911
Cafe1942