zoukankan      html  css  js  c++  java
  • Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) B. Code obfuscation 水题

    B. Code obfuscation

    题目连接:

    http://codeforces.com/contest/765/problem/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".

    Sample Input

    abacaba

    Sample Output

    YES

    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.

    题意

    有一个人想混淆代码,于是他把第一个出现的变量变成a,第二个出现的变量变成b……

    然后这样混淆下去。

    现在给你一个代码,里面只有变量,把空格和换行符都删去之后,问你这个代码可不可能是混淆之后的代码。

    题解:

    照着题意模拟就好了。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    int now = 0;
    int vis[26];
    int main()
    {
        string s;
        cin>>s;
        for(int i=0;i<s.size();i++){
            if(vis[s[i]-'a'])continue;
            if(now==(int)(s[i]-'a')){
                vis[s[i]-'a']=1;
                now++;
                continue;
            }
            cout<<"NO"<<endl;
            return 0;
        }
        cout<<"YES"<<endl;
    }
  • 相关阅读:
    Leetcode929.Unique Email Addresses独特的电子邮件地址
    Leetcode914.X of a Kind in a Deck of Cards卡牌分组
    new Date()设置日期在IOS的兼容问题
    koa2 使用passport权限认证中间件
    当 better-scroll 遇见 Vue
    百度地图开发
    通过Ajax方式上传文件,使用FormData进行Ajax请求
    app中页面滑动,防止a链接误触
    js判断是微信、QQ内置浏览器打开页面
    百度天气预报接口介绍
  • 原文地址:https://www.cnblogs.com/qscqesze/p/6401421.html
Copyright © 2011-2022 走看看