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

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

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替换没有被a替换的变量名,以此类推,问最后给的字符串是不是符合规定

解法:第一个字母一定是a,然后再依次出现b,c,d,重复出现是跳过,出现中断说明不符合

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 string s;
 4 int main()
 5 {
 6     map<char,int>q;
 7     map<char,int>::iterator it;
 8     cin>>s;
 9     if(s[0]!='a')
10     {
11         cout<<"NO";
12     }
13     else
14     {
15         int flag='a';
16         for(int i=0;i<s.length();i++)
17         {
18             if((int)s[i]==flag)
19             {
20                 flag++;
21                 q[s[i]]=1;
22             }
23             else if(q[s[i]])
24             {
25                 continue;
26             }
27             else
28             {
29                 cout<<"NO";
30                 return 0;
31             }
32         }
33         cout<<"YES";
34     }
35     return 0;
36 }

 

posted @ 2017-02-14 20:15  樱花落舞  阅读(322)  评论(0编辑  收藏  举报