Responsive image

问题 2224 --B. Alphabetical Strings

2224: B. Alphabetical Strings

时间限制: 2 Sec  内存限制: 512 MB
提交: 1  解决: 1
[提交][状态][讨论版][命题人:]

题目描述

A string ss of length nn (1≤n≤26) is called alphabetical if it can be obtained using the following algorithm:

  • first, write an empty string to ss (i.e. perform the assignment ss := "");
  • then perform the next step nn times;
  • at the ii-th step take ii-th lowercase letter of the Latin alphabet and write it either to the left of the string ss or to the right of the string ss (i.e. perform the assignment ss := c+sc+s or ss := s+cs+c, where cc is the ii-th letter of the Latin alphabet).

In other words, iterate over the nn first letters of the Latin alphabet starting from 'a' and etc. Each time we prepend a letter to the left of the string ss or append a letter to the right of the string ss. Strings that can be obtained in that way are alphabetical.

For example, the following strings are alphabetical: "a", "ba", "ab", "bac" and "ihfcbadeg". The following strings are not alphabetical: "z", "aa", "ca", "acb", "xyz" and "ddcba".

From the given string, determine if it is alphabetical.


输入描述

The first line contains one integer tt (1≤t≤10000) — the number of test cases. Then tt test cases follow.

Each test case is written on a separate line that contains one string ss. String ss consists of lowercase letters of the Latin alphabet and has a length between 11 and 2626, inclusive.

输出描述

Output tt lines, each of them must contain the answer to the corresponding test case. Output YES if the given string ss is alphabetical and NO otherwise.

You can output YES and NO in any case

样例输入

11
a
ba
ab
bac
ihfcbadeg
z
aa
ca
acb
xyz
ddcba

样例输出

YES
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO

来源

[提交][状态]
ACM算法攻关部
  • Anything about this OnlineJudge, Please Contact Administrator. Click add QQ

    OJ system based on HUSTOJ Project , UI based on Twitter Bootstrap

    Copyright 2016 ACM算法攻关部
    关于网站改版