Description
把 n n 个单词转化为个字母,规则如下,首先把第一个单词转化为字母 a a ,对于之后的每个单词,如果该单词之前出现过,就同样的把这个单词转化成其之前转化的字母,如果没有出现就按顺序拿一个没有使用过的字母来转化,现在给出个字母,问这 n n 个字母是否为一次合法的转化结果
Input
一个只由小写字母组成的字符串
Output
如果合法则输出 YES Y E S ,否则输出 NO N O
Sample Input
abacaba
Sample Output
YES
Solution
简单题,记录已经使用的字母的最大编号,当前字母要么不超过该编号表示之前已经出现过,要么为该编号后一个字母,否则不合法
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define maxn 1111
char s[maxn];
int main()
{
while(~scanf("%s",s))
{
int pre='a'-1,gg=0,n=strlen(s);
for(int i=0;i<n;i++)
if(s[i]<=pre)continue;
else if(s[i]==pre+1)pre=s[i];
else
{
gg=1;
break;
}
printf("%s\n",gg?"NO":"YES");
}
return 0;
}