#include<iostream>
#include<string>
using namespace std;
string cypher;
void decypher()
{
for (;;)
{
int right = cypher.find_first_of(']');
if (-1 == right)
return;
int left = cypher.substr(0, right).find_last_of('[');
string sub = "", temp = "";
int length = 0;
if (isdigit(cypher[left + 2]))
{
length = (cypher[left + 1] - '0') * 10 + cypher[left + 2] - '0';
sub = cypher.substr(left + 3, right - left - 3);
}
else
{
length = cypher[left + 1] - '0';
sub = cypher.substr(left + 2, right - left - 2);
}
for (int i = 0; i < length; i++)
temp += sub;
cypher = cypher.substr(0, left) + temp + cypher.substr(right + 1);
}
}
int main()
{
cin >> cypher;
decypher();
cout << cypher;
return 0;
}
洛谷P1928 外星密码进阶解法
最新推荐文章于 2025-04-02 13:22:54 发布
本文展示了一个C++程序,用于解密特定格式的字符串。程序通过查找字符串中的括号对,根据括号内的数字重复子字符串,从而实现解密。输入解密的字符串后,程序将输出解密后的结果。该代码适用于理解和实践字符串操作及循环结构。
993

被折叠的 条评论
为什么被折叠?



