time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

A string ss of length nn (1≤n≤261≤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.

Input

The first line contains one integer tt (1≤t≤1041≤t≤104) — 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

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 (for example, strings yEs, yes, Yes and YES will be recognized as a positive answer).

Example

input

Copy

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

output

Copy

YES
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO

Note

The example contains test cases from the main part of the condition.

解题说明:此题是一道字符串题,s必定是从字母a开始相加 所以先找到字母a的下标 然后定义2个指针l,r 依次向左和向右走 如果这2个指针可以走到头 说明是s的子串。

#include<bits/stdc++.h>
using namespace std;
string s;
int t;
int main()
{cin >> t;while (t--){cin >> s;int l = s.size();int It = 0, rt = l - 1;bool f = 1;while (l != 0){if (s[It] == l + 'a' - 1){It++;}else if (s[rt] == l + 'a' - 1){rt--;}else{f = 0;break;}l--;}if (f == 0){cout << "NO" << "\n";}else{cout << "YES" << "\n";}}return 0;
}

B. Alphabetical Strings相关推荐

  1. Codeforces Round #731 (Div. 3)(ABCDEFG)

    A. Shortest Path with Obstacle 当两个点的x坐标或者y坐标相同的时候,需要多花2费绕开 #include<bits/stdc++.h> using names ...

  2. Day 3 CF731div3 vp

    这场我不好说,我感觉我是逆天,div3的C题都卡了很久,想太复杂了,一直wa2,结果没发现这么简单,越打越低能了属于是: 然后赛后一下子把D和E给1A了,乐 群友说,比赛的时候卡题的话,如果40分钟连 ...

  3. codeforces 112APetya and Strings(字符串水题)

    A. Petya and Strings 点击打开题目 time limit per test 2 seconds memory limit per test 256 megabytes input ...

  4. Petya and Strings

    文章目录 一.Petya and Strings 总结 一.Petya and Strings 本题链接: 题目: A. Petya and Strings time limit per test2 ...

  5. Android TextView 在strings 里面 实现换行

    在TextView 把text 使用快捷键放到strings 里面 \n是无法被放到里面的 如果想实现换行 可以手动在里面添加 \n 例如写了一个小例子, 如果你写了多语言适配 ,那么在你的其他的st ...

  6. Go 学习笔记(51)— Go 标准库之 strings(字符串比较、字符串前后缀、字符串统计、字符串索引、字符串包含、字符串转换、字符串复制、字符串替换、字符串去除、字符串分割和连接)

    1. 概述说明 import "strings" strings 包实现了用于操作字符的简单函数. strings 包与 bytes 包中的函数用法基本一样. 2. 主要函数 2. ...

  7. Simple Dynamic Strings(SDS)源码解析和使用说明二

    在<Simple Dynamic Strings(SDS)源码解析和使用说明一>文中,我们分析了SDS库中数据的基本结构和创建.释放等方法.本文将介绍其一些其他方法及实现.(转载请指明出于 ...

  8. Simple Dynamic Strings(SDS)源码解析和使用说明一

    SDS是Redis源码中一个独立的字符串管理库.它是由Redis作者Antirez设计和维护的.一开始,SDS只是Antirez为日常开发而实现的一套字符串库,它被使用在Redis.Disque和Hi ...

  9. golang strings.Fields 使用

    2019独角兽企业重金招聘Python工程师标准>>> s := "Hello 世\n界!\tHe\vl\flo!" ss := strings.Fields(s ...

最新文章

  1. 玩转Parse(第一篇:新手入门)
  2. rsa加密算法java实例,java实现的RSA加密算法详解
  3. docker 升级版本
  4. vc2008编译libjpeg
  5. 【天线的主要技术指标及其含义-带宽 】
  6. 去除WMP10上面的东方宽屏图标
  7. Win11有几个版本 Windows 11各版本区别对比
  8. 文件操作——getc()和putc()函数
  9. 数据预处理阶段“不处理”缺失值的思路
  10. 你的记忆里有黄金矿工吗?
  11. Linux系统查看发行版本
  12. 2021强网杯 Web赌徒 WP
  13. android壁纸应用,HPSTR - 可能是你见过最会玩的壁纸应用 - Android 应用 - 【最美应用】...
  14. VM虚拟机安装篇·VMware Workstation Pro(虚拟机)安装Win10操作系统(图文介绍超详细)
  15. backtrack回溯算法
  16. 汽车之家联席总裁邵海峰
  17. 【黑金ZYNQ7000系列原创视频教程】01.熟悉vivadomdash;mdash;纯逻辑led实验
  18. 用来测试的在线小视频url地址
  19. 北京内推 | ​轻舟智航自动驾驶感知组招聘深度学习算法实习生
  20. UG NX 12 图形区

热门文章

  1. 工贸一体型企业外贸管理软件解决方案丨汇信外贸软件
  2. 删除电话和调制解调器选项里的我的位置里面的区号
  3. opencv FFMpeg写视频报错 [mp4 @ 0xcb0f40] Tag mp4v/0x7634706d incompatible with output codec id '13
  4. 使用Python,Opencv检测AprilTag
  5. 2023.3.6-3.12 AI行业周刊(第140期):AI视觉算法开发平台
  6. 匹配字符串 正则表达式
  7. C语言最简单的排序——冒泡排序
  8. mac最好的免费下载工具:Progressive Downloader for Mac
  9. VMware如何使用NAT上网
  10. Laravel使用token验证登录