Müller tried to catch Stierlitz red-handed many times, but always failed because Stierlitz could ever find some excuse. Once Stierlitz was looking through his email messages. At that moment, Müller
entered secretly and watched a meaningless sequence of symbols appear on the screen. “A cipher message,” Müller thought. “UTF-8,” Stierlitz thought.
It is known that Stierlitz ciphers messages by the following method.
- He deletes all spaces and punctuation marks.
- He replaces all successive identical letters by one such letter.
- He inserts two identical letters at an arbitrary place many times.
Try to restore a message as it was after the second step. For that, remove from the message all pairs of identical letters inserted at the third step.
Input
The only input line contains a message ciphered by Stierlitz. The message consists of lowercase English letters and its length is at most 200000.
Output
Output the restored message.
Sample
input
output
wwstdaadierfflitzzz
|
stierlitz
|
这道题目其实十分有趣的。
如果按照原文叙述求思考,那么就很可能犯错的。
我们应该换一个角度来思考。
题目的意思就变成:
如果字符重复出现的次数是双次,那么就删除这个字符,如果出现的次数是单次,那么就保留这个字符。
这样诠释之后,题目豁然开朗,原来就是一个简单的操作字符串的问题。
这样写不会有bug。网上有些这道题目的AC程序是有bug的,应付不了所有特殊情况,不过这道题的测试用例似乎不是那么强,没有全面地测试所有特殊情况。
下面看我的程序,十分简洁明了的,速度也相当快0.04ms:
#include <string>
#include <iostream>
using namespace std;
void CipherMessage1654()
{
string s;
cin>>s;
int c = 1;
string rs;
for (int i = 0; i < (int)s.size(); i++)
{
if (rs.empty() || rs.back() != s[i])
{
if (c % 2 == 0) rs.pop_back();
if (!rs.empty() && rs.back() == s[i]) c = 2;
else
{
rs.push_back(s[i]);
c = 1;
}
}
else c++;
}
if (c % 2 == 0 && !rs.empty()) rs.pop_back();
cout<<rs;
}
int main()
{
CipherMessage1654();
return 0;
}
分享到:
相关推荐
AES加密的几张方法包括javax.crypto.Cipher 的net实现方式
javax.crypto.Cipher; javax.crypto.KeyGenerator; javax.crypto.spec.SecretKeySpec等
Fundamentals.Cipher407
1.from Crypto.Cipher import AES 报错:cannot import name '_AES' 2.下载附件的,把附件的文件替换到python安装目录下的对应位置
Pet Translator_1.1_anti_anti.apk.cipher
encryptRule: encryptors: aes_encryptor: type: aes props: aes.key.value: 123456abc tables: t_user: columns: pwd: cipherColumn: pwd encryptor: aes_encryptor ...query.with.cipher.column: false
raise NotImplementedError("Use module Crypto.Cipher.PKCS1_OAEP instead") NotImplementedError: Use module Crypto.Cipher.PKCS1_OAEP instead SOLUTION pip uninstall pycryptodome pip uninstall pycrypto ...
1.from Crypto.Cipher import AES 报错:cannot import name '_AES' 2.下载附件的,把附件的文件替换到python安装目录下的对应位置
Uninstall_Statistics 统计 应用 自身被 卸载 Android statistics application is uninstalled 参考自这篇blog http://www.cnblogs.com/zealotrouge/p/3157126.html ...
打开android上 cipher 加密的db, 用于查看微信数据库!
cipher.init(Cipher.ENCRYPT_MODE, key, sr); // 执行加密操作 bytes = cipher.doFinal(bytes); // 返回字节数组 return bytes; } /** * 设置key文件路径 * @param keyfile String */ public void ...
多表密码破解密文,在我的博文中详细介绍了该密文的破解过程,希望能够得到大家借鉴
欣技盘点机 编程平台-FastCollect(版本:1.12.5) 不需要写一行代码,只需要简单地勾选,即可100%满足您的需要。 10分钟即可完成程序的编写。普通的C编程一般需要一两周的时间,而且维护很麻烦,当需求改变时往往...
HILL密码加密解密算法实现,仿射密码的加密解密实现
Column permutation cipher是基于置换的加密解密方式。利用本程序可实现Column permutation cipher的加密和解密。
SM2、SM3、SM4国密算法软实现,已经通过国家标准预设定参数进行测试,可直接使用。
sqlcipher 数据的查看工具 对应sqlcipher 3.0及以上 sqlcipher 2.x加密的不可以 需使用 http://download.csdn.net/detail/zhanghw0917/7931759
at javax.crypto.Cipher.getInstance(Cipher.java:656) at javax.crypto.Cipher.getInstance(Cipher.java:595) ... 12 more Caused by: java.util.jar.JarException: file:/opt/code/signal-Server-master/target...
Qt中SQlite数据库加密SqliteCipher 操作实例,打开多个数据库,附着数据库跨库查询, 对应说明:https://blog.csdn.net/woguanni/article/details/120524602
cipher.exe