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 ...
随机推荐
- 初识Java——第一章 初识Java
1. 计算机程序: 为了让计算机执行某些操作或解决某个问题而编写的一系列有序指令的集合. 2. JAVA相关的技术: 1).安装和运行在本机上的桌面程序 2).通过浏览器访问的面向 ...
- tornado用户指引(二)------------tornado协程实现原理和使用(一)
摘要:Tornado建议使用协程来实现异步调用.协程使用python的yield关键字来继续或者暂停执行,而不用编写大量的callback函数来实现.(在linux基于epoll的异步调用中,我们需要 ...
- ORALCE表的约束条件
一.主键:(PRIMARY KEY) 主键是表中的一列或多列.为表定义主键有如下几个作用: 1.主键包含的列不能输入重复的值,以此来保证一个表的所有行的唯一性: 2.主键也不允许定义此约束的列为NUL ...
- CentOS 7.x下升级Python版本到3.x系列(新老版本共存)
由于python官方已宣布2.x系列即将停止支持,为了向前看,我们升级系统的python版本为3.x系列服务器系统为当前最新的CentOS 7.4 1.安装前查看当前系统下的python版本号 # p ...
- 使用TryParse()来执行数值转换
static void Main() { var ageText = "25"; if (int.TryParse(ageText,out int age)) { Console. ...
- 分清clientY pageY screenY layerY offsetY的区别
分清clientY pageY screenY layerY offsetY的区别 在我们想要做出拖拽这个效果的时候,我们需要分清这几个属性的区别,这几个属性都是计算鼠标点击的偏移值,我们需要对其进行 ...
- S3C2440启动程序运行过程
s3c2440有两种启动方式,一种Nor flash 启动,一种Nand flash 启动. 由于NAND FLASH是接在NAND FLASH控制器上而不是系统总线上,所以没有在S3C2440A的8 ...
- Learning notes | Data Analysis: 1.2 data wrangling
| Data Wrangling | # Sort all the data into one file files = ['BeijingPM20100101_20151231.csv','Chen ...
- Git Status 中文乱码解决
现象: jb@H39:~/doc$ git statusOn branch masterYour branch is up-to-date with 'origin/master'. Untracke ...
- Hibernate怎么用
一.为什么用Hibernate? [核心:对象关系映射] Hibernate是对jdbc的轻量级封装,可以简化数据库连接操作, 在该框架之前,数据库的操作步骤是: 1.根据连接字串获取连接 2.执行s ...