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 ...
随机推荐
- 阿里云centOS7.4上MySql5.6安装
最近一个项目要部署在阿里云上,为了开发团队方便,我自费买了个ECS,先装个数据库给开发用. 因为之前都是在真机安装,与这次阿里云上的部署比起来,还是有点区别的. Mysql 1 安装mysql版本包 ...
- java读取xml文件的四种方法
Xml代码 <?xml version="1.0" encoding="GB2312"?> <RESULT> <VALUE> ...
- linux简单文件管理命令的使用
在linux系统中,命令的使用要方便于图形界面的使用,上一个博客介绍了如何使用PuTTy远程登录linux,当然,我使用的是本地登录(手动滑稽) 经过一星期课余时间的了解,大致了解了一些简单的文件管理 ...
- 06JavaScript变量
JavaScript 变量 变量是用于存储信息的"容器". var x=5; var y=6; var z=x+y; 就像代数那样 x=5 y=6 z=x+y 在代数中,我们使用字 ...
- jQuery关于复选框的基本小功能
这里是我初步学习jquery后中巨做的一个关于复选框的小功能: 点击右边选项如果勾上,对应的左边三个小项全部选中,反之全不选, 左边只要有一个没选中,右边大项就取消选中,反之左边全部选中的话,左边大项 ...
- mysql 导出行数据到txt文件,指定字符分割
select id,name, concat('tel:',phone) from user order by time INTO outfile 'user.txt' FIELDS terminat ...
- Linux的基础命令大全
linux的基础命令大全 1.shell是系统的用户界面,提供了用户与内核进行交互操作的一种接口(命令解释器) ls -al /bin/sh ls -al /bin/bash 查看这些shell的 ...
- python教程(二)·变量
什么是变量?在百度百科中,变量的解释是: 变量来源于数学,是计算机语言中能储存计算结果或能表示值抽象概念.变量可以通过-- 这是一段很长很长的解释,其实,作者认为没必要这么机械式的去理解.简单说,变量 ...
- Leecode刷题之旅-C语言/python-344反转字符串
/* * @lc app=leetcode.cn id=344 lang=c * * [344] 反转字符串 * * https://leetcode-cn.com/problems/reverse- ...
- MCUXpresso release build 时提示GFLIB等函数未引用的问题
MCUXpresso release build 时提示 GFLIB 等函数未引用的问题 最近在使用 MCUXpresso 编译工程时选择 Debug(Debug build) 能顺利编译,但是选择 ...