【CF 1144A】Diverse Strings 简单set

                                       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.

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 nn 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<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))

int main()
{
	int n,i;
	string a;
	cin>>n;
	while(n--)
	{
		cin>>a;
		set<char>s;
		for(i=0;i<a.length();i++)
			s.insert(a[i]);
		if(s.size()==a.length())
		{
			set<char>::iterator it;
			int flag=0,ff=0;
			char x;
			for(it=s.begin();it!=s.end();it++)
			{
				//cout<<*it; 
				if(!ff)
				{
					x=*it;
					ff=1;
					continue;
				}
				if(*it!=x+1)
					flag=1;
				else
					x=*it;
			}
			if(!flag)
				cout<<"Yes"<<endl;
			else
				cout<<"No"<<endl;
		}
		else
			cout<<"No"<<endl;
	}
	return 0;
}

 

全部评论

相关推荐

11-28 13:56
已编辑
吉林建筑大学
所有好工作吻上来:最近可能压力比较大吧,面试的时候已经不屑于去说一些违心的话了,今天这场面试我真是没控制住啊,感觉我已经要发火了
实习学到最有价值的工作习...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务