A. Diverse Strings

A string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exactly once. For example, the following strings are diverse: "fced", "xyz", "r" and "dabcef". The following string are not diverse: "az", "aa", "bad" and "babc". Note that the letters 'a' and 'z' are not adjacent.

Formally, consider positions of all letters in the string in the alphabet. These positions should form contiguous segment, i.e. they should come one by one without any gaps. And all letters in the string should be distinct (duplicates are not allowed).

You are given a sequence of strings. For each string, if it is diverse, print "Yes". Otherwise, print "No".

Input

The first line contains integer nn (1≤n≤1001≤n≤100), denoting the number of strings to process. The following nn lines contains strings, one string per line. Each string contains only lowercase Latin letters, its length is between 11 and 100100, inclusive.

Output

Print n

代码:

 #include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main() {
int n;
bool flag=true;
cin>>n;
while(n--) {
char s[];
int a[];
cin>>s;
int len=strlen(s);
for (int i = ; i < len; i++) {
a[i]=s[i]-'';
}
sort(a,a+len);
for(int i=; i<len-; i++) {
if((a[i+]-a[i])!=) {
flag=false;
break;
}
}
if(flag) {
cout<<"Yes"<<endl;
} else {
cout<<"No"<<endl;
}
flag=true;
}
}

思路分析:对字符转整数排序,要是差不为1就输出no,否则输出yes。

题目链接:https://codeforces.com/contest/1144/problem/A

Codeforces1144A(A题)Diverse Strings的更多相关文章

  1. (原创)Codeforces Round #550 (Div. 3) A Diverse Strings

    A. Diverse Strings time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. leetcode 第42题 Multiply Strings

    题目:Given two numbers represented as strings, return multiplication of the numbers as a string. Note: ...

  3. LeetCode算法题-Add Strings(Java实现)

    这是悦乐书的第223次更新,第236篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第90题(顺位题号是415).给定两个非负整数num1和num2表示为字符串,返回num ...

  4. LeetCode算法题-Isomorphic Strings(Java实现)

    这是悦乐书的第191次更新,第194篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第50题(顺位题号是205).给定两个字符串s和t,确定它们是否是同构的.如果s中的字符 ...

  5. [LeetCode] 大数问题,相加和相乘,题 Multiply Strings

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  6. CF1144A Diverse Strings 题解

    Content 我们定义一个字符串是合法的,当且仅当这个字符串是"连续排列"(按照字母表顺序排序).现在给出 \(n\) 个字符串 \(s_1,s_2,s_3,...,s_n\), ...

  7. Leetcode OJ 刷题

    Valid Palindrome吐槽一下Leetcode上各种不定义标准的输入输出(只是面试时起码能够问一下输入输出格式...),此篇文章不是详细的题解,是自己刷LeetCode的一个笔记吧,尽管没有 ...

  8. #C++初学记录(ACM试题1)

    A - Diverse Strings A string is called diverse if it contains consecutive (adjacent) letters of the ...

  9. CodeForces Round #550 Div.3

    http://codeforces.com/contest/1144 A. Diverse Strings A string is called diverse if it contains cons ...

随机推荐

  1. PHP的yield是个什么玩意

    来源:https://segmentfault.com/a/1190000018457194 其实,我并不是因为迭代或者生成器或者研究PHP手册才认识的yield,要不是协程,我到现在也不知道PHP中 ...

  2. 2019-2020-1 20199325《Linux内核原理与分析》第五周作业

    第五周作业主要是选择一个系统调用(13号系统调用time除外),使用库函数API和C代码中嵌入汇编代码两种方式使用同一个系统调用,在实验楼Linux虚拟机环境下完成实验. 系统调用的列表参见 http ...

  3. 【linux三剑客】sed命令

    sed - stream editor for filtering and transforming text sed 流编辑器 strem edition,实现对文件的增删改替换查是Linux中第二 ...

  4. 【Linux常见命令】dos2unix命令,unix2dos命令

    我们都知道.打回车键就是换行的意思. 在不同系统下打回车键效果是不同的: MAC OS下:dakdhih \r LINUX下:dakdhih \n DOS\WINDOWS下:dakdhih \r\n ...

  5. Get on the CORBA

    from: <The Common Object Request Broker: Architecture and Specification> Client To make a requ ...

  6. Joomla CMS 3.2-3.4.4 SQL注入 漏洞分析

    RickGray · 2015/10/26 11:24 昨日,Joomla CMS发布新版本3.4.5,该版本修复了一个高危的SQL注入漏洞,3.2至3.4.4版本都受到影响.攻击者通过该漏洞可以直接 ...

  7. Github作为Maven仓库

    新建发布构件项目 新建一个普通的maven项目,坐标为 创建一个类: 接着在pom文件中添加: <distributionManagement> <repository> &l ...

  8. 数学--数论--POJ1365——Prime Land

    Description Everybody in the Prime Land is using a prime base number system. In this system, each po ...

  9. FileStream提示文件正在由另一进程使用的解决方法

    文件正在由另一进程使用…… FileStream fs = new FileStream(strFilePath, FileMode.Open,FileAccess.Read,FileShare.Re ...

  10. Spring源码学习01:IntelliJ IDEA2019.3编译Spring5.3.x源码

    目录 Spring源码学习01:IntelliJ IDEA2019.3编译Spring5.3.x源码 前言 工欲善其事必先利其器.学习和深读Spring源码一个重要的前提:编译源码到我们的本地环境.这 ...