**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. 服务器部署nginx报错 nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored

    nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored 修改nginx配置参数后,使用ng ...

  2. iOS 8 AutoLayout与Size Class自悟

    前言 iOS8和iPhone6发布已经过去蛮久了,广大的果粉终于迎来了大屏iPhone,再也不用纠结为大屏买三星舍苹果了…但是对于iOS开发人员来说,迎来了和Android开发开发一样的问题—> ...

  3. iOS - UIScreen的 bound、frame、scale属性

    A UIScreen object contains the bounding rectangle of the device’s entire screen. When setting up you ...

  4. 模拟线程安全的售票案例(java)

    package try51.thread.safe; import java.util.ArrayList; import java.util.Random; import java.util.con ...

  5. java虚拟机的符号引用和直接引用

    在java中,一个java类将会编译成一个class文件.在编译时,java类并不知道引用类的实际内存地址,因此只能使用符号引用来代替.比如org.simple.People类引用org.simple ...

  6. linux下pip安装pygame

    在学习python的过程中要用到pygame,在安装过程中遇到一些问题,经百度解决.因为使用的版本为python3,故以下教程针对python3版本.安装教程如下: 一.首先你要确保你已经安装了pip ...

  7. sftp本地上传和远程下载

    1.  打开SecureCRT 连接相应的主机 2.  打开会话后,使用快捷键 alt + p,进入 sftp> 界面 3.  查看 sftp 相应的命令 help 4.  常用命令 (1)查看 ...

  8. Circular reference 循环引用 第二联系人

    A circular reference is a series of references where the last object references the first, resulting ...

  9. centos source install

    CentOS Kernel Source Install Mar 12th, 2012 | Comments CentOS kernel source install, first off if yo ...

  10. html中一些文字标签

    <!DOCTYPE html><html><head> <meta charset="utf-8"> <title>菜鸟 ...