**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 n (1≤n≤100), denoting the number of strings to process. The following n lines contains strings, one string per line. Each string contains only lowercase Latin letters, its length is between 1 and 100, inclusive.

Output

Print n lines, one line per a string in the input. The line should contain "Yes" if the corresponding string is diverse and "No" if the corresponding string is not diverse. You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.

Example

Input

8

fced

xyz

r

dabcef

az

aa

bad

babc

Output

Yes

Yes

Yes

Yes

No

No

No

No

正确代码

#include<cstdio>
#include<cstring>
int main(){
char a[105];
int t;
scanf("%d", &t);
while(t--){
memset(a, 0, sizeof(a));
scanf("%s", a);
int len = strlen(a), flag = 0;
for(int i = 0; i < len; i++){
for(int j = i+1; j < len; j++){
if(a[i] > a[j]){
char temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
for(int i = 1; i < len; i++){
if(a[i] - a[i-1] != 1){
printf("No\n");
flag = 1;
break;
}
}
if(flag == 1){
continue;
}else{
printf("Yes\n");
}
}
return 0;
}

题目理解

该题较为简单,该题的正确做法是对输入的字母进行判断,若有相近的字母则输出YES,若没有则输出NO,若输入的是单个字符则也输出YES。

相关知识点

%s是进行字符串的整体输入,即

int c[200];
scanf("%s",%c);

是将整个字符串拆分成单个字符储存进数组a,即输入abcde则a[1]=b。以及对单个字符进行判断,判断只需要在判断NO和YES是加一点小聪明.

        for(int i = 1; i < len; i++){
if(a[i] - a[i-1] != 1){
printf("No\n");
flag = 1;
break;
}
}
if(flag == 1){
continue;
}else{
printf("Yes\n");

在这个if条件判断中,因为单个字符的长度len=1,所以在进行No的判断中是不符合的,因为No的判断条件是i=1;i<len;因此直接进行else循环。

#C++初学记录(ACM试题1)的更多相关文章

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

    Max Sum Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-seq ...

  2. #C++初学记录ACM补题(D. Candies!)前缀和运算。

    D - Candies!   Consider a sequence of digits of length [a1,a2,-,a]. We perform the following operati ...

  3. #C++初学记录(acm试题#预处理)

    C - Lucky 7 in the Pocket BaoBao loves number 7 but hates number 4, so he refers to an integer as a ...

  4. #C++初学记录(set进阶#acm cf 190802 B. Subsegments)

    B. Subsegments#set进阶 Programmer Sasha has recently begun to study data structures. His coach Stas to ...

  5. #C++初学记录(sort函数)

    sort函数 前言:当进行贪心算法的学习时,需要用到sort函数,因为初学c++汇编语言,sort的具体用法没有深入学习,所以这里进行sort学习记录并只有基础用法并借用贪心算法题目的代码. 百度百科 ...

  6. 完成了C++作业,本博客现在开始全面记录acm学习历程,真正的acm之路,现在开始

    以下以目前遇到题目开始记录,按发布时间排序 ACM之递推递归 ACM之数学题 拓扑排序 ACM之最短路径做题笔记与记录 STL学习笔记不(定期更新) 八皇后问题解题报告

  7. javaweb初学记录

    原文 链接 http://blog.csdn.net/iojust/article/details/52429805 - ---热情依旧 - 环境搭建: - jdk环境配置 jdk下载: http:/ ...

  8. #C++初学记录(算法4)

    A - Serval and Bus It is raining heavily. But this is the first day for Serval, who just became 3 ye ...

  9. 北大ACM试题分类+部分解题报告链接

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...

随机推荐

  1. Word 2013无法启用Restrict Editing解决方法

    当前文档可能是Mail Merge Letter type document,MAILINGS -> Start Mail Merge -> Normal Word Document保存即 ...

  2. 在openLdap上添加memberOf属性

    我为openldap添加memberof属性的时候参考了这个文章:http://www.adimian.com/blog/2014/10/how-to-enable-memberof-using-op ...

  3. DragonBones龙骨换装(局部换装+全局换装)

    参考: Egret官方换装动画 Egret换装三种方式 CSDN(全局换装) egret使用DragonBones实现简单的换装 换装,主要是替换任意插槽的图片,来达到局部换装的目的. 游戏中可以只制 ...

  4. 【OOP】C++ const成员函数

    预备知识 1.代码转换分析技巧 在早期某些编译器会将C++代码翻译为C代码,然后使用C编译器生成可执行文件.其中翻译的一个转化就是:将this指针显式添加到成员函数的第一个参数位置上,并在成员函数调用 ...

  5. web自动化时,sendkeys输入长文本时浏览器响应慢或错误时处理

    在做某个测试时,要在文本框中输入大量的文本,文件内容如下: "-----BEGIN CERTIFICATE-----\nMIIBozCCAQwCAQEwDQYJKoZIhvcNAQEFBQA ...

  6. A simple guide to 9-patch for Android UI

    extends:http://radleymarx.com/blog/simple-guide-to-9-patch/ While I was working on my first Android ...

  7. 数据库操作相关(sql语句-php)

    文件:db.config.smarty.php 这个文件主要是用于数据库配置 <?php $db = array( 'host'=>'localhost', 'user'=>'roo ...

  8. nginx 开机自动启动

    接下来聊一聊nginx的开机自启吧 看了看都是用脚本启动的,我也就不扯啥犊子了,都是前人经验 我的操作系统是centos 7 nginx版本是1.10.3 首先看一下自己的nginx配置 我的是 ./ ...

  9. ZooKeeper (一)概览

    注:出于记录对 zookeeper 的学习研究成果目的,并分享经验,根据官方文档翻译整理而成本文,原文地址: http://zookeeper.apache.org/doc/trunk/zookeep ...

  10. 服务器推技术研究Comet

    服务器推技术 最近参与的一个关于股票的项目,有这样一个需求.服务器需要主动推送给客户端消息.这和传统的Web模式不同.传统的Web系统,客户端和服务器的交互是这样的: 客户端先和服务器建立一个TCP连 ...