-->
当前位置:首页 > 题库

PROGRAMMING:Stack operation legitimacy

Luz5年前 (2021-05-10)题库500
Suppose that's' and 'x' denote the stack in and stack out operations respectively. If an empty stack is operated on according to a sequence composed of only's' and 'x', the corresponding operation is feasible (if there is no stack empty when deletion occurs) and the last state is also stack empty, then the sequence is a legal stack operation sequence. Please write a program, input's' and 'x' sequence to judge whether the sequence is legal.
###Input format:
The first line of input gives two positive integers n and m, where n is the number of sequences to be tested and m ($$\ Le 50 $$) is the maximum capacity of the stack. Then n lines, each line gives a sequence consisting only of's' and 'x'. The sequence should not be empty and the length should not exceed 100.
###Output format:
For each sequence, output 'yes' on one line if the sequence is a legal stack operation sequence, or' no 'if it is not.
###Input example:
```in
4 10
SSSXXSXXSX
SSSXXSXXS
SSSSSSSSSSXSSXXXXXXXXXXX
SSSXXSXXX
```
###Output example:
```out
YES
NO
NO
NO
```






answer:If there is no answer, please comment