#K50687. Transaction Sequence Validator
Transaction Sequence Validator
Transaction Sequence Validator
You are given a sequence of transactions represented as a string consisting solely of the characters D
(deposit) and W
(withdrawal).
A transaction sequence is considered valid if and only if it satisfies all the following conditions:
- It contains at least one deposit (
D
). - It contains at least one withdrawal (
W
). - There are no two consecutive withdrawals (i.e. the substring
WW
should not appear).
Given multiple transaction sequences, your task is to determine for each sequence if it is valid. For each sequence, output YES
if it is valid, otherwise output NO
.
The conditions in mathematical notation can be written in \( \LaTeX \) as follows:
\(\text{Valid} \iff (\exists\, D \in \text{sequence}) \wedge (\exists\, W \in \text{sequence}) \wedge \neg(\text{'WW'} \subset \text{sequence})\)
inputFormat
The input is read from standard input and has the following format:
T sequence_1 sequence_2 ... sequence_T
where:
T
is an integer representing the number of transaction sequences.- Each
sequence_i
is a string which only contains the charactersD
andW
.
outputFormat
For each transaction sequence, print a line with YES
if the sequence is valid or NO
if it is not.
The output should be written to standard output.
## sample3
DDDW
DW
DWW
YES
YES
NO
</p>