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 ...
随机推荐
- Linux 日常操作
Linux 日常操作 */--> Linux 日常操作 Table of Contents 1. 查看硬件信息 1.1. 服务器型号序列号 1.2. 主板型号 1.3. 查看BIOS信息 1.4 ...
- http_response_code()和header()
1.http_response_code — 获取/设置响应的 HTTP 状态码向服务器发送成功状态码:http_response_code(200); 返回值如果提供了response_code,将 ...
- memcache雪崩
缓存雪崩一般是由某个缓存节点失效,导致其他节点的缓存命中率下降, 缓存中缺失的数据(memcache经典场景,当有一个客户端的服务请求过来的时候,首先去查memcache,memcache里面是否缓存 ...
- Data Flow Diagram with Examples - Customer Service System
Data Flow Diagram with Examples - Customer Service System Data Flow Diagram (DFD) provides a visual ...
- [Windows] Socket Server Failed to bind, error 10048
Address already in use. Typically, only one usage of each socket address (protocol/IP address/port) ...
- zookeeper笔记(一)
title: zookeeper笔记(一) zookeeper 安装简记 解压文件 $ tar -zxvf zookeeper-3.4.10.tar.gz -C 安装目录 创建软连接(进入安装目录) ...
- 李宏毅机器学习--PM2.5预测
一.说明 给定训练集train.csv,要求根据前9个小时的空气监测情况预测第10个小时的PM2.5含量. 训练集介绍: (1).CSV文件,包含台湾丰原地区240天的气象观测资料(取每个月前20天的 ...
- swift 3.0字符串的简单使用
let str:String = "12314124" 获取某个指定位置的元素 print(str.characters[str.index(str.startIndex, off ...
- Jmeter 后置处理器
1.JSON Extractor Json extractor 后置处理器用在返回格式为 Json 的 HTTP 请求中,用来获取返回的 Json 中的某个值.并保存成变量供后面的请求进行调用或断言等 ...
- 请不要浪费你的生命,一文多发推广就用它(OpenWrite)
你我的共同困惑 你是否跟我一样?刚开始尝试写作,自己没有名气,有以下几个困惑: 想要推广自己,想在多个平台发文? 多平台发文之后,想要看各个平台的流量如何? 有了流量,想要引流用户到自己的网站? 网站 ...