No.438 Introduction to Cww Programming
Problem Statement
There is a programming language called Cww.
A Cww source code is executable when it satisfies the following conditions.
・ The source code consists only of the 4 kinds of characters 'c','w','C','W'.
・ The source code consists of a single-line string (a newline is required at the end).
Let $S$ be an executable Cww source code (string).
The Cww executor takes $S$ as input and operates as follows.
(Reference: Wikipedia Stack)
・ The Cww executor has a stack. The stack initially contains $0$ elements.
・ Let $S_i$ be the $i$-th character of $S$. The executor reads $S_1,S_2,,,$ in order from left to right.
・ When the program reads the character 'c', the integer $x$ is added to the top of the stack.
・ When the program reads the character 'w', the integer $y$ is added to the top of the stack.
・ Let $a$ be the $1$st element from the top of the stack and $b$ be the $2$nd element from the top of the stack. When the program reads the character 'C', it removes $a,b$ from the stack and adds $a + b$ to the top of the stack.
・ Let $a$ be the $1$st element from the top of the stack and $b$ be the $2$nd element from the top of the stack. When the program reads the character 'W', it removes $a,b$ from the stack and adds $a - b$ to the top of the stack.
・ When there are no more characters for the program to read, the program removes the integer $z$ at the top of the stack, outputs $z$, and terminates.
・ When the program removes an element from the stack, if the stack is empty, the program results in an error (WA) and terminates. Note that reading 'C' or 'W' removes 2 elements from the stack.
Now, cww, a beginner at Cww, is writing a program in Cww that outputs a certain integer $z$.
Given integers $x,y,z$, create for cww one Cww source code that outputs $z$.
However, since cww is a beginner, source code that is too long cannot be read.
Therefore, the source code you output must be at most $10000$ characters, excluding the newline.
If it is impossible in any way to output $z$ within $10000$ characters, output the string "NO" on one line.
Input
$x$ $y$ $z$
$0 \le x,y,z \le 100000000$
Output
$S$
$S$ must be a Cww source code that outputs $z$, with $1 \le |S| \le 10000$.
If no source code that outputs $z$ can be constructed, output ”NO” on one line.
Except for the ”NO” case, outputting any character other than ’c’,’w’,’C’,’W’ in $S$ results in an error.
Print a newline at the end.
Sample
Sample 1
Input
1 2 3
Output
cwC
When the source code is "cwC", the program operates as follows.
[ ] ... stack
'c' : add $x=1$ to the stack [1]
'w' : add $y=2$ to the stack [12]
'C' : remove $2,1$ from the stack and add $2+1 = 3$ [3]
Therefore, the source code "cwC" outputs the 3 remaining on the stack.
"wcC", "wwCcWccWW", and others are also correct.
Sample 2
Input
2 3 7
Output
cwwCwCW
When the source code is "cwwCwCW", the program operates as follows.
[ ] ... stack
'c' : add $x=2$ to the stack [2]
'w' : add $y=3$ to the stack [23]
'w' : add $y=3$ to the stack [233]
'C' : remove $3,3$ from the stack and add $3+3 = 6$ [26]
'w' : add $y=3$ to the stack [263]
'C' : remove $3,6$ from the stack and add $3+6 = 9$ [29]
'W' : remove $9,2$ from the stack and add $9-2 = 7$ [7]
Therefore, the source code "cwwCwCW" outputs the 7 remaining on the stack.
Sample 3
Input
42 72 88
Output
NO
Under the constraints, no correct source code can be created,
so output "NO" instead.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
btk
🍡yurahuna