欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1644A.Doors and Keys
Doors and Keys
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 () — 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.
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.
Samples
4
rgbBRG
RgbrBG
bBrRgG
rgRGBb
YES
NO
YES
NO
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |