Codeforces Round #397(Div. 1 + Div. 2 combined)B. Code obfuscation【水题】
来源:互联网 发布:淘宝卖农副产品挣钱吗 编辑:程序博客网 时间:2024/05/18 13:47
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 symbola, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences withb, 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.
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.
If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO".
abacaba
YES
jinotega
NO
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 withc, the result would be "a b a c a b a",
- all identifiers have been replaced, thus the obfuscation is finished.
题目大意:
现在给你一个已经混淆了的字符串,问你是否能够是通过某种字符串得到的。
混淆字符串的机制:对于原串来讲,对于第一种出现的字符,全部替代为a.对于第二种出现的字符,全部替代为b.................依次类推。
思路:
对于出现字母的顺序,肯定是a.b.c.d.e............才是YES的字符串。
那么对于当前字符,如果是之前没出现过的,那么必须是出现过的最大的字母顺序+1才行。
Ac代码:
#include<stdio.h>#include<string.h>using namespace std;int main(){ char a[505]; int vis[505]; while(~scanf("%s",a)) { memset(vis,0,sizeof(vis)); int n=strlen(a); int now=1; int flag=0; for(int i=0;i<n;i++) { if(vis[i]==0) { if(now!=a[i]-'a'+1)flag=1; else { for(int j=i;j<n;j++) { if(a[j]==a[i])vis[j]++; } } now++; } } if(flag==1)printf("NO\n"); else printf("YES\n"); }}
- Codeforces Round #397(Div. 1 + Div. 2 combined)B. Code obfuscation【水题】
- Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1 线段树
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) -- B. Verse Pattern(水题)
- Codeforces Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) 部分题解
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)【A,B,C,D】
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) -- B. Batch Sort(暴力枚举)
- Codeforces Round #397(Div. 1 + Div. 2 combined)A. Neverending competitions【水题】
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- qt mingw版本编译报错:incorrect register `%rax' used with `l' suffix
- 分类和聚类的区别
- 121. Best Time to Buy and Sell Stock -Easy
- spring boot mybatis 简单整合使用
- 10马踏棋盘之中国象棋
- Codeforces Round #397(Div. 1 + Div. 2 combined)B. Code obfuscation【水题】
- 【bzoj1036】树的统计 树链剖分/LCT
- Eclipse解决“Archive for required library: ...”错误
- 程序员必备基础知识:通信协议——Http、TCP、UDP
- 内联函数和宏定义的区别
- Android开发中Animation动画详解
- session详解
- 大数阶乘
- 简单谈谈JavaScript中的this