2201_75561378 2022-11-30 20:04 采纳率: 0%
浏览 12

这个程序为啥没法运行(不是我写的)


#include<iostream>
#include<string>
using namespace std;
string Decode(string& s)
{
int i = 0;
int x = -1;
int y = -1;
int z = -1;
int sz = s.size();
while (i < sz)
{
if (s[i] == '[')
{
x = i;
}
else if (s[i] == ',')
{
y = i;
}
else if (s[i] == ']')
{
z = i;
break;
}
i += 1;
}
if (x != -1 && y != -1 && z != -1)
{
int times = (int(s[x + 1])) - 48;
string sub;
string sub_times ;
sub = s.substr(y + 1, z - (y + 1));
for (int i = 0; i < times; i++)
{
sub_times += sub;
}
string decode_str;
decode_str = s.substr(0, x) + sub_times + s.substr(z + 1, sz - (z + 1));
return Decode(decode_str);
}
return s;
}
int main()
{
string s;
cin >> s;
string decode_str;
decode_str = Decode(s);
cout << decode_str << endl;
​}
  • 写回答

2条回答 默认 最新

  • Huazie 优质创作者: 编程框架技术领域 2022-11-30 20:42
    关注

    你说的是 哪样的不能运行? 这段程序 要 输入 一个字符串,才能往后执行的。

    评论

报告相同问题?

问题事件

  • 创建了问题 11月30日