2023-06-21 19:37:01 来源 : 哔哩哔哩
The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.
【资料图】
In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.
Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.
The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters:
R, G, B — denoting red, green and blue doors, respectively;
r, g, b — denoting red, green and blue keys, respectively.
Each of these six characters appears in the string exactly once.
The knight is standing at the beginning of the hallway — on the left on the map.
Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway.
Input
The first line contains a single integer t (1≤t≤720) — the number of testcases.
Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once.
Output
For each testcase, print YES if the knight can open all doors. Otherwise, print NO.
Example
input
4
rgbBRG
RgbrBG
bBrRgG
rgRGBb
output
YES
NO
YES
NO
Note
In the first testcase, the knight first collects all keys, then opens all doors with them.
In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.
In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.
In the fourth testcase, the knight can't open the blue door.
中文翻译:
骑士站在一条狭长的走廊前。 一位公主在它的尽头等待着。
走廊里有三扇门:红门、绿门和蓝门。 然而,这些门是一个接一个地放置的,顺序可能不同。 要前往下一扇门,骑士必须先打开前面的门。
每扇门只能用相应颜色的钥匙打开。 因此,三把钥匙:一把红钥匙、一把绿钥匙和一把蓝钥匙——也被放置在走廊的某个地方。 要打开门,骑士应该首先拿起其颜色的钥匙。
骑士有一张走廊的地图。 它可以转录为一个字符串,由六个字符组成:
R、G、B——分别表示红、绿、蓝门;
r、g、b——分别表示红、绿、蓝键。
这六个字符中的每一个都在字符串中恰好出现一次。
骑士站在走廊的尽头——地图的左边。
给定一张走廊地图,确定骑士是否可以打开所有门并在走廊尽头与公主见面。
只要前面出线小写的字母,后面匹配大写的字母就可以的。也可以用string.indexof()去判断也可以的,我是用的集合跟数量来判断的;
下面是代码:
标签: