zoukankan      html  css  js  c++  java
  • CodeForces765B

    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.
     1 //2017-02-14
     2 #include <iostream>
     3 #include <cstdio>
     4 #include <cstring>
     5 
     6 using namespace std;
     7 
     8 int book[30];
     9 
    10 int main()
    11 {
    12     string S;
    13     char cur_max;
    14     bool fg;
    15     while(cin>>S)
    16     {
    17         fg = true;
    18         memset(book, 0, sizeof(book));
    19         for(int i = 0; i < S.length(); i++)
    20               book[S[i]-'a']++;
    21         for(int i = 1; i < 26; i++)
    22               if(book[i]!=0 && book[i-1]==0)
    23             {
    24                 fg = false;
    25                 break;
    26             }
    27         cur_max = S[0];
    28         if(cur_max != 'a')fg = false;
    29         for(int i = 1; i < S.length(); i++)
    30         {
    31             if(S[i]>cur_max && S[i]-cur_max==1)cur_max = S[i];
    32             else if(S[i]>cur_max && S[i]-cur_max>1){
    33                 fg = false;
    34                 break;
    35             }
    36         }
    37         if(fg)cout<<"YES"<<endl;
    38         else cout<<"NO"<<endl;
    39     }
    40 
    41     return 0;
    42 }
  • 相关阅读:
    Java虚拟机一览表
    Java程序员的10道XML面试题
    bzoj 1644: [Usaco2007 Oct]Obstacle Course 障碍训练课【spfa】
    bzoj 1703: [Usaco2007 Mar]Ranking the Cows 奶牛排名【bitset+Floyd传递闭包】
    bzoj 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝【dp+树状数组】
    bzoj 2100: [Usaco2010 Dec]Apple Delivery【spfa】
    bzoj 2015: [Usaco2010 Feb]Chocolate Giving【spfa】
    bzoj 1741: [Usaco2005 nov]Asteroids 穿越小行星群【最大点覆盖】
    bzoj 1645: [Usaco2007 Open]City Horizon 城市地平线【线段树+hash】
    bzoj 2060: [Usaco2010 Nov]Visiting Cows 拜访奶牛【树形dp】
  • 原文地址:https://www.cnblogs.com/Penn000/p/6399385.html
Copyright © 2011-2022 走看看