zoukankan      html  css  js  c++  java
  • cf397 B. Code obfuscation

    B. Code obfuscation
    time limit per test2 seconds
    memory limit per test512 megabytes
    inputstandard input
    outputstandard 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……….的大小排列,必须按顺序,能出现比它上一个最大字母小的,但不能比它大。

    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<cstdlib>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    char str[505];
    int main()
    {
        scanf("%s",str);
        int len=strlen(str);
        char a='a';//赋值时,字母要加单引号
        int flag=0;
        for(int i=0;i<len;i++)
        {
            if(str[i]==a)//这两个地方不用加单引号,否则表示字母a,也就是数字97
            {
                a=a+1;
            }
            else if(str[i]<a)
            {
                continue;
            }
            else if(str[i]>a)
            {
                flag=1;
                printf("NO
    ");
                break;
            }
        }
        if(flag==0)
        {
            printf("YES
    ");
        }
        return 0;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    "No regrets."
  • 相关阅读:
    微软新一代Surface,该怎么看?
    Windows 8创新之路——样章分享
    微软新一代Surface发布,参数曝光
    从MS Word到Windows Live Writer
    《计算机科学基础》学习笔记_Part 1 Computer and Data
    我看Windows 8.1
    Hyper-V初涉_早期Windows安装虚拟硬件驱动
    2020.09.05【省选组】模拟 总结
    2020.08.15【NOIP提高组】模拟 总结
    2020.08.14【省选B组】模拟 总结
  • 原文地址:https://www.cnblogs.com/zxy160/p/7215147.html
Copyright © 2011-2022 走看看