Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) B - Code obfuscation

地址:http://codeforces.com/contest/765/problem/B

题目:

B. Code obfuscation
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

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".

Examples
input
abacaba
output
YES
input
jinotega
output
NO
Note

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.

 思路:如果合法,出现的最大字母依次是a,b,c,d....

  直接扫一遍即可

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 #define MP make_pair
 6 #define PB push_back
 7 typedef long long LL;
 8 typedef pair<int,int> PII;
 9 const double eps=1e-8;
10 const double pi=acos(-1.0);
11 const int K=1e5+7;
12 const int mod=1e9+7;
13 
14 char ss[K],mx='a'-1;
15 int ff;
16 int main(void)
17 {
18    cin>>ss;
19    for(int i=0,len=strlen(ss);i<len;i++)
20     if(ss[i]<=mx)
21         ;
22     else if(ss[i]==mx+1)
23         mx++;
24     else
25         ff=1;
26     if(ff)
27         printf("NO\n");
28     else
29         printf("YES\n");
30     return 0;
31 }

 

posted @ 2017-02-20 18:52  weeping  阅读(115)  评论(0编辑  收藏  举报