CF1547B Alphabetical Strings(了解字符串的的一些规律)

简介: CF1547B Alphabetical Strings(了解字符串的的一些规律)

Alphabetical Strings



time limit per test2 seconds

memory limit per test512 megabytes

inputstandard input

outputstandard output


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


first, write an empty string to s (i.e. perform the assignment s := “”);

then perform the next step n times;


at the i-th step take i-th lowercase letter of the Latin alphabet and write it either to the left of the string s or to the right of the string s (i.e. perform the assignment s := c+s or s := s+c, where c is the i-th letter of the Latin alphabet).


In other words, iterate over the n first letters of the Latin alphabet starting from ‘a’ and etc. Each time we prepend a letter to the left of the string s or append a letter to the right of the string s. 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 t (1≤t≤10^4) — the number of test cases. Then t test cases follow.


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


Output

Output t lines, each of them must contain the answer to the corresponding test case. Output YES if the given string s 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


inputCopy

11

a

ba

ab

bac


ihfcbadeg

z

aa

ca

acb

xyz

ddcba


outputCopy

YES

YES

YES

YES

YES

NO

NO

NO

NO

NO

NO


Note

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


题意分析


生成一个字符串(字符都是小写字母)。生成规则如下:


·初始字符串是空的。


·每次在前面或后面加入一个字符,第 ii 次加入的字符是小写字母表中第 ii 个小写字母。


给一些字符串,请判断是否可以被生成出来。


做法



显然若字符串中字符的出现并不连续或者同一个字符出现了两次,那么该串是不行的。


举个栗子:dba,bab。


然后我们看:每次字母从小到大加,且加在两侧,那是不是中间的字符会比旁边的小呢?


有了这些结论,这题就做完了,上代码。

#include<bits/stdc++.h>
using namespace std;
int main()
{
  int t;
  cin>>t;
  while(t--)
  {
    string s;
    cin>>s;
    int l=0;
    int r=s.size()-1;
    while(l<=r)
    {
      if((s[l]-'a')==r-l)
      l++;
      else if((s[r]-'a')==r-l)
      r--;
      else break; 
    }
    if(l>r)
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl; 
  }
 } 


相关文章
|
5月前
|
数据采集 存储 JSON
基于录音转写与大模型的家装客户概览生成实践
针对家装行业长录音(常超万字)设计客户概览系统:通过语音转写、角色区分、语义分段、结构化事实提取、历史数据融合及多层校验,精准提炼家庭情况、需求、预算、顾虑等关键信息,确保每项结论可追溯、无混淆,赋能销售与设计高效决策。
|
11月前
|
Web App开发 网络协议 安全
HTTP/1.1到HTTP/3:互联网通信协议的三代演进之路
HTTP/1.1奠定基础,HTTP/2优化性能,HTTP/3颠覆底层。从队头阻塞到多路复用,从TCP到QUIC,三代协议演进推动互联网通信迈向低延迟、高并发、强安全的新时代。
1507 5
|
5月前
|
数据采集 人工智能 API
GEO优化岗位工作SOP:标准作业流程全解析
本文档聚焦GEO(生成式引擎优化)岗位实操,提炼“Geo专家于磊”多年验证的五阶段闭环SOP:诊断基准→内容增益→实体构建→技术适配→监测迭代。拒绝空谈概念,直击执行标准与避坑指南,团队可即查即用。
986 0
|
8月前
|
人工智能 自然语言处理 运维
适合金融行业用的智能体产品(AI工具)有哪些?金融垂直领域智能体解决方案:头部厂商与新兴黑马一览
IDC报告指出,金融行业正从“工具赋能”迈向“智能重构”,AI升维为驱动业务与生产关系变革的核心力量。生成式AI已形成完整生态,聚焦智能体应用落地。银行业重风控运营,证券业强投顾资管,保险业突出营销服务。智能体正深度渗透研报分析、信贷审批、智能投顾、AI核保等高频场景,加速金融智能化转型。(239字)
|
9月前
|
算法 搜索推荐 JavaScript
阿里国际站代运营底层逻辑拆解:硬核防坑与推荐算法逆向工程
B2B外贸SEO重在获取真实采购询盘,而非泛流量。本文直击阿里国际站流量瓶颈根源,拆解L4推荐算法与重复铺货风险,提出“单品爆破+精准长尾矩阵”白帽策略,强调语义匹配、Dwell Time优化与权重聚拢,助力出海企业突破降权困局。(239字)
1259 1
|
10月前
|
安全 物联网 C++
微调是否会削弱 base model 的原始安全对齐
本文揭示微调对大模型安全对齐的隐性侵蚀:安全并非静态“外壳”或可锁定模块,而是与全部参数纠缠的行为偏好分布。微调(尤其SFT、LoRA、PPO)不删除安全能力,却系统性“重加权”其触发条件——稀释犹豫、压缩拒答、掩盖灰区风险。真正危险的,是变化未被察觉。安全需被主动守护,而非默认留存。
|
自然语言处理 数据可视化 数据挖掘
提升效率必看:从0到1的看板工具任务分组方法全解析
本文系统介绍看板任务分组方法,通过可视化工作流、限制在制品、优化流动与持续改进,提升团队协作效率。结合多项目管理、客户服务等场景,详解如何按项目、优先级、负责人等维度分组,并以板栗看板为例演示实操步骤,辅以Python自动化技巧与Q&A,助力团队实现高效、灵活的任务管理。
|
人工智能 监控 小程序
【快递鸟】选择对接你的物流商城/小程序的物流API平台
在电商竞争日益激烈的今天,物流体验已成为影响用户留存和复购的关键因素。一个高效、透明、稳定的物流系统,对于物流商城或小程序来说至关重要。然而,自建物流查询系统需要对接众多快递公司,开发周期长、维护成本高、数据整合困难。
792 0
|
搜索推荐 索引 Python
使用Python批量生成个性化奖状
本文介绍了如何使用Python结合Pandas和python-pptx库,根据Excel数据表自动批量生成个性化PowerPoint格式的奖状文件,详细步骤包括导入库、读取数据、替换模板占位符及保存文件,有效提升工作效率。
892 64
|
传感器 人工智能 API
通义灵码2.5深度评测:编程智能体与MCP工具的革新体验
通义灵码2.5通过“智能体+MCP”组合,重新定义了AI编码助手的边界。其价值不仅在于代码生成效率,更在于通过工具链整合和环境感知,推动开发流程向“声明式编程”演进。对于开发者而言,它既是提升效率的利器,也是探索AI辅助开发边界的实验场。
1150 8