Code obfuscatio (翻译!)
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
YES
jinotega
NO
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.
题目意思:Kostya尝试使用小写字母来替换变量名,先从a替换第一个变量名以及后面相同的变量一次类推,问最后所给的字符串是否是一个合法的字符串。
解题思路:这道题可以理解为每一个字母后面可以出现它本身或者比它大的字母,当然字母出现要符合26个英文字母的出现顺序。我可以使用两个循环,遍历整个字符串,每当后面出现和前面相同的字母,我就标记一下,当再换另一个字母的时候也要判断是否按照26字母排序,以此类推。
上代码:
#include<stdio.h>
#include<string.h>
int main()
{
char s[],c;
int v[];
int i,j,k,flag;
gets(s);
memset(v,,sizeof(v));
flag=;
k=strlen(s);
c='a';
for(i=; i<k; i++)
{
if(v[i]==)
{
if(c!=s[i])
{
flag=;
break;
}
else
{
for(j=i; j<k; j++)
{
if(s[j]==s[i])
{
v[j]=;
}
}
}
c++;
}
}
if(flag==)
printf("NO\n");
else
printf("YES\n");
return ;
}
双重循环之中做标记这种方法很是常用,通过判断是否之前出现过或者是否再次被利用,减少了循环次数,缩短了运行时间。
Code obfuscatio (翻译!)的更多相关文章
- 1.2 Simple Code!(翻译)
Simple Code! 简洁编码 Playing football is very simple, but playing simple football is the hardest thing ...
- 计算机程序的思维逻辑 (38) - 剖析ArrayList
从本节开始,我们探讨Java中的容器类,所谓容器,顾名思义就是容纳其他数据的,计算机课程中有一门课叫数据结构,可以粗略对应于Java中的容器类,我们不会介绍所有数据结构的内容,但会介绍Java中的主要 ...
- 在Application中集成Microsoft Translator服务之使用http获取服务
一.创建项目 首先我们来创建一个ASP.NET Application 选择时尚时尚最时尚的MVC,为了使演示的Demo更简单,这里选择无身份验证 二.创建相关类 项目需要引入之前两个类AdmAcce ...
- PEP 8
官方文档: PEP 8 :Style Guide for Python Code 部分翻译: http://www.blogjava.net/lincode/archive/2011/02/02/34 ...
- 如何设计PHP业务模块(函数/方法)返回结果的结构?
如题:如何设计业务模块返回结果的结构? 一个业务函数/方法执行后,对外输出数据的结构通常有以下几种: 1.返回数字,如 成功时返回 0,失败时返回 -1,有的还会用一个全局变量输出错误信息: < ...
- (原创)3.2 AddOwner和OverrideMetadata的区别
1 AddOwner和OverrideMetadata 1.1 分析 从源代码上看,AddOwner函数中调用了OverrideMetadata, 并且把本类和依赖属性的哈希值加入到依赖属性的一张哈希 ...
- Hex、bin、axf、elf格式文件小结
转自Hex.bin.axf.elf格式文件小结 一.HEX Hex文件,一般是指Intel标准的十六进制文件.Intelhex 文件常用来保存单片机或其他处理器的目标程序代码.它保存物理程序存储区中的 ...
- hex和bin文件格式的区别
Intel HEX文件是记录文本行的ASCII文本文件,在Intel HEX文件中,每一行是一个HEX记录,由十六进制数组成的机器码或者数据常量.Intel HEX文件经常被用于将程序或数据传输存储到 ...
- 用 C++ 标准模板库(STL)的 vector 实现二叉搜索树(BST)
本文由 Justme0翻译自 Code Project 转载请参见文章末尾处的要求. 介绍 众所周知,要建一棵树,我们需要关注它的内存分配与释放.为了避开这个问题,我打算用C++ STL(vector ...
随机推荐
- sass的嵌套
sass的嵌套包括两种: 1.选择器的嵌套.(最常用到) 指的是在一个选择器中嵌套另一个选择器来实现继承,从而增强了sass文件的结构性和可读性. 在选择器嵌套中,可以使用&表示父元素选择器 ...
- Flask之Flask实例有哪些参数
常用的参数应用实例 from flask import Flask, render_template, url_for, session, request, redirect app = Flask( ...
- 【Hadoop故障处理】全分布下,DataNode进程正常启动,但是网页上不显示,并且DataNode节点为空
[故障背景] DataNode进程正常启动,但是网页上不显示,并且DataNode节点为空. /etc/hosts 的ip和hostname配置正常,各个机器之间能够ping通. [日志错误信息] ...
- 2.2 vivi虚拟视频驱动测试
学习目标:在linux终端安装xawtv,并测试vivi.ko驱动程序. 一.安装xawtv 1)ubuntu能上网情况下,使用命令:# sudo apt-get install xawtv 2)如果 ...
- java 深入理解引用类型
该博客原创自某位博主,原创博客链接https://www.cnblogs.com/SilentCode/p/4858790.html 本人在全文通读的基础上修改了原文的一点小bug,并在原文基础上继续 ...
- python--模块之基本
模块的概念: 在计算机程序开发过程中,随着程序代码越来越多,在一个文件里代码就会越来越长,不利于维护.为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样每个文件包含的代码就相对较少. ...
- pix2code开发笔记
1.软件安装 首先需要安装Python3和pip (1) Python3 环境搭建 Window 平台安装 Python: https://www.python.org/downloads/wind ...
- 20145234黄斐《Java程序设计》第六周学习总结
教材学习内容总结 第十章 输入/输出 文件的读写 网络上传数据的基础 父类 InputStream与OutputStream 流(Stream)是对「输入输出」的抽象,注意「输入输出」是相对程序而言的 ...
- 天津Uber优步司机奖励政策(12月28日到12月29日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- Unknown host 'services.gradle.org' 解决方法
报错如下: Unknown host 'services.gradle.org'. You may need to adjust the proxy settings in Gradle. Learn ...