Coffee Machine
Limits: 2 sec., 512 MiB
This statement was translated automatically from Ukrainian.
Zenyk recently got a job in an office, and now he has received his
first unexpected task: to find the coffee machine. Zenyk’s office is
quite spacious and is located in a long corridor of \(n\) sections of equal width. Each section
can contain a workstation, a coffee machine, or empty space. Zenyk
doesn’t know yet which workstation is his, but he doesn’t like walking a
lot. Therefore, he asked you to help him find the distance to the
nearest coffee machine for each workstation. A workstation in the
corridor is denoted by the English letter W, and a coffee
machine by the letter C. The symbol . denotes
that the passage has neither a workstation nor a coffee machine. The
distance between adjacent sections is equal to one meter.
Input
The only line of the input contains a string \(s\) consisting only of characters
W, C, and ., which denote a
workstation, a coffee machine, and a free passage, respectively.
Output
Print a sequence of numbers corresponding to the minimum distance (in meters) to the nearest coffee machine for each workstation, in the same order in which these workstations are located in the string \(s\) (from left to right).
Constraints
\(2 \le |s| \le 1000\).
It is guaranteed that there is at least one coffee machine and at least one workstation.
The scoring consists of the following blocks:
1 point for each example from the problem statement,
10 points: the number of workstations is equal to 1,
15 points: the number of coffee machines is equal to 1,
20 points: all workstations are located to the left of all coffee machines,
53 points: no additional constraints.
You will receive the points for a block only if your program passes all tests in that block.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| W...C......W | 4 7 |
| Input (stdin) | Output (stdout) |
|---|---|
| C...W......C | 4 |
Notes
The distance between a workstation and a coffee machine is defined as the number of sections between them. In the first case, there is only one machine. In the second case, it is optimal for Zenyk to go to the leftmost coffee machine. The distance between it and the machine is equal to 4.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|