Codeforces1144A(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".
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.
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。
Codeforces1144A(A题)Diverse Strings的更多相关文章
- (原创)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 ...
- leetcode 第42题 Multiply Strings
题目:Given two numbers represented as strings, return multiplication of the numbers as a string. Note: ...
- LeetCode算法题-Add Strings(Java实现)
这是悦乐书的第223次更新,第236篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第90题(顺位题号是415).给定两个非负整数num1和num2表示为字符串,返回num ...
- LeetCode算法题-Isomorphic Strings(Java实现)
这是悦乐书的第191次更新,第194篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第50题(顺位题号是205).给定两个字符串s和t,确定它们是否是同构的.如果s中的字符 ...
- [LeetCode] 大数问题,相加和相乘,题 Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- CF1144A Diverse Strings 题解
Content 我们定义一个字符串是合法的,当且仅当这个字符串是"连续排列"(按照字母表顺序排序).现在给出 \(n\) 个字符串 \(s_1,s_2,s_3,...,s_n\), ...
- Leetcode OJ 刷题
Valid Palindrome吐槽一下Leetcode上各种不定义标准的输入输出(只是面试时起码能够问一下输入输出格式...),此篇文章不是详细的题解,是自己刷LeetCode的一个笔记吧,尽管没有 ...
- #C++初学记录(ACM试题1)
A - Diverse Strings A string is called diverse if it contains consecutive (adjacent) letters of the ...
- CodeForces Round #550 Div.3
http://codeforces.com/contest/1144 A. Diverse Strings A string is called diverse if it contains cons ...
随机推荐
- HTML H5响应式,表格,表单等
HTML杂项 响应式图片 <img srcset="elva-fairy-320w.jpg 320w, elva-fairy-480w.jpg 480w, elva-fairy-800 ...
- 2019-2020-1 20199308《Linux内核原理与分析》第九周作业
<Linux内核分析> 第八章 可执行程序工作原理进程的切换和系统的一般执行过程 8.1 知识点 进程调度的时机 ntel定义的中断类型主要有以下几种 硬中断(Interrupt) 软中断 ...
- Spring5参考指南:SpringAOP简介
文章目录 AOP的概念 Spring AOP简介 Spring AOP通知类型 写过程序的都知道OOP即面向对象编程. 从最开始的面向过程编程,到后面的面向对象编程,程序的编写方式发生了重大的变化,面 ...
- 曹工力荐:调试 jdk 中 rt.jar 包部分的源码(可自由增加注释,修改代码并debug)
背景 大家知道,jdk安装的目录下,一般会有个src.zip包,这个包基本对应了rt.jar这个包.rt.jar这个包里面,就放了jdk中,jdk采用java实现的那部分类库代码,比如java.lan ...
- 广深小龙-基于unittest、pytest自动化测试框架之demo来学习啦!!!
基于unittest.pytest自动化测试框架之demo,赶紧用起来,一起学习吧! demo分为两个框架:①pytest ②unittest demo 中 包含 web.api 自动化测试框架 ...
- 【Linux常见命令】mkdir命令
mkdir - make directories 例子: mkdir /data 在根目录/下创建data文件夹(目录) 语法: mkdir [-p] dirName 参数说明: -p 确保目录名称存 ...
- 虚拟化VMware之虚拟机备份(1)
之虚拟机备份() 模版:是一种开放,公用.安全的虚拟机压缩格式,通常使用的是扩展名为.ova可以在多个主流虚拟化平台下进行操作 是和 通过技术协作推出的基于磁盘的备份和恢复的新一代解决方案,可靠且易部 ...
- CSS开发技巧(一):button样式设置
button样式需要注意的有几点: 1.建议有一个最小宽度,以免在文字很少时使得按钮过于窄,宽高不协调: 2.建议有一个padding,以免内部文本显得过于拥挤: 2.hover时需要有颜色变化,以告 ...
- linux之centos安装jdk以及nginx详细过程
一.安装jdk 1:首先下载jdk到本地,然后通过git 上传到linux服务器上 2:进入目录usr,并创建目录java,将jdk的压缩文件移动到该目录下 cd /usr mkdir java mv ...
- 使用SWIG将C++接口转换成Java接口
PS:此文章仅作为个人记录使用,代码属于私密,故无法公开: 以C++类classifier为例,文件保存于百度网盘 https://pan.baidu.com/s/1c2AwhaS(需密码) 系统:U ...