Code obfuscatio (翻译!)

本文介绍了一种基于字母顺序的代码混淆算法,通过逐一代替程序中的标识符实现代码的混淆,确保每个标识符被唯一的小写字母代替,并探讨了如何验证一个字符串是否能通过该算法产生。

Description

Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.

To obfuscate the code, Kostya first looks at the first variable name used in his program and replaces all its occurrences with a single symbol a, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences with b, and so on. Kostya is well-mannered, so he doesn't use any one-letter names before obfuscation. Moreover, there are at most 26 unique identifiers in his programs.

You are given a list of identifiers of some program with removed spaces and line breaks. Check if this program can be a result of Kostya's obfuscation.

Input

In the only line of input there is a string S of lowercase English letters (1 ≤ |S| ≤ 500) — the identifiers of a program with removed whitespace characters.

Output

If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO".

Sample Input

Input
abacaba
Output
YES
Input
jinotega
Output
NO

Hint

In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program:

  • replace all occurences of number with a, the result would be "a string a character a string a",
  • replace all occurences of string with b, the result would be "a b a character a b a",
  • replace all occurences of character with c, the result would be "a b a c a b a",
  • all identifiers have been replaced, thus the obfuscation is finished.

 

 

题目意思:Kostya尝试使用小写字母来替换变量名,先从a替换第一个变量名以及后面相同的变量一次类推,问最后所给的字符串是否是一个合法的字符串。

解题思路:这道题可以理解为每一个字母后面可以出现它本身或者比它大的字母,当然字母出现要符合26个英文字母的出现顺序。我可以使用两个循环,遍历整个字符串,每当后面出现和前面相同的字母,我就标记一下,当再换另一个字母的时候也要判断是否按照26字母排序,以此类推。

 

上代码:

 1 #include<stdio.h>
 2 #include<string.h>
 3 int main()
 4 {
 5     char s[501],c;
 6     int  v[501];
 7     int i,j,k,flag;
 8     gets(s);
 9     memset(v,0,sizeof(v));
10     flag=1;
11     k=strlen(s);
12     c='a';
13     for(i=0; i<k; i++)
14     {
15         if(v[i]==0)
16         {
17             if(c!=s[i])
18             {
19                 flag=0;
20                 break;
21             }
22             else
23             {
24                 for(j=i; j<k; j++)
25                 {
26                     if(s[j]==s[i])
27                     {
28                         v[j]=1;
29                     }
30                 }
31             }
32             c++;
33         }
34     }
35     if(flag==0)
36         printf("NO\n");
37     else
38         printf("YES\n");
39     return 0;
40 }

 

双重循环之中做标记这种方法很是常用,通过判断是否之前出现过或者是否再次被利用,减少了循环次数,缩短了运行时间。

 

 

转载于:https://www.cnblogs.com/wkfvawl/p/8716004.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值