CF1765B.Broken Keyboard
入门
通过率:0%
时间限制:1.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Recently, Mishka started noticing that his keyboard malfunctions — maybe it's because he was playing rhythm games too much. Empirically, Mishka has found out that every other time he presses a key, it is registered as if the key was pressed twice. For example, if Mishka types text, the first time he presses a key, exactly one letter is printed; the second time he presses a key, two same letters are printed; the third time he presses a key, one letter is printed; the fourth time he presses a key, two same letters are printed, and so on. Note that the number of times a key was pressed is counted for the whole keyboard, not for each key separately. For example, if Mishka tries to type the word osu, it will be printed on the screen as ossu.
You are given a word consisting of n lowercase Latin letters. You have to determine if it can be printed on Mishka's keyboard or not. You may assume that Mishka cannot delete letters from the word, and every time he presses a key, the new letter (or letters) is appended to the end of the word.
最近,Mishka 开始注意到他的键盘出现了故障——这可能是因为他玩节奏类游戏玩得太多了。通过实验观察,Mishka 发现:每次他按键时,键盘的响应呈现周期性规律:奇数次按键(第 1、3、5… 次)仅输入一个字符;偶数次按键(第 2、4、6… 次)则会重复输入两个相同的字符。例如,若 Mishka 输入文本,第一次按键输出恰好一个字母;第二次按键输出两个相同字母;第三次按键输出一个字母;第四次按键输出两个相同字母,依此类推。注意:按键次数是针对整个键盘统计的,而非每个键单独计数。例如,若 Mishka 尝试输入单词 osu,屏幕上实际显示为 ossu。
给定一个由 n 个小写拉丁字母组成的单词。你需要判断该单词是否可能由 Mishka 的键盘输出。你可以假设 Mishka 无法删除已输入的字母,且每次按键后,新输入的字母(或字母对)均被追加到当前单词末尾。
输入格式
The first line of the input contains one integer t (1≤t≤100) — the number of test cases.
The first line of the test case contains one integer n (1≤n≤100) — the length of the word.
The second line of the test case contains a string s consisting of n lowercase Latin letters — the word that should be checked.
输入的第一行包含一个整数 t(1≤t≤100)—— 表示测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤100)—— 表示单词的长度。
每个测试用例的第二行包含一个由 n 个小写拉丁字母组成的字符串 s —— 即需要检查的单词。
输出格式
For each test case, print YES if the word s can be printed on Mishka's keyboard, and NO otherwise.
对于每个测试用例,如果单词 s 可以在 Mishka 的键盘上打印出来,则输出 YES;否则输出 NO。
输入输出样例
输入#1
4 4 ossu 2 aa 6 addonn 3 qwe
输出#1
YES NO YES NO
说明/提示
In the first test case, Mishka can type the word as follows: press o (one letter o appears at the end of the word), then presses s (two letters s appear at the end of the word), and, finally, press u (one letter appears at the end of the word, making the resulting word ossu).
In the second test case, Mishka can try typing the word as follows: press a (one letter a appears at the end of the word). But if he tries to press a one more time, two letters a will appear at the end of the word, so it is impossible to print the word using his keyboard.
In the fourth test case, Mishka has to start by pressing q. Then, if he presses w, two copies of w will appear at the end of the word, but the third letter should be e instead of w, so the answer is NO.
在第一个测试用例中,Mishka 可以按如下方式输入该单词:先按 o(单词末尾出现一个字母 o),然后按 s(单词末尾出现两个字母 s),最后按 u(单词末尾出现一个字母 u,得到最终单词 ossu)。
在第二个测试用例中,Mishka 可尝试按如下方式输入该单词:先按 a(单词末尾出现一个字母 a)。但如果他再按一次 a,则单词末尾将出现两个字母 a,因此无法使用他的键盘打印出该单词。
在第四个测试用例中,Mishka 必须首先按 q。接着,如果他按 w,则单词末尾将出现两个 w,但第三个字母应为 e 而非 w,因此答案为 NO。
输入解题思路,AI测评打分。不知道怎么写?