求救
查看原帖
求救
1617786
XsIeEiKcEk楼主2025/1/18 15:56

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
string s;
int i;
bool in;

string dg(int x) {
	int j = x + 1;
	bool it = false;
	string temp = "";
	int add = s[x] - '0';
	if (s[x + 1] < 'A') {
		add = add * 10 + s[x + 1] - '0';
		j++;
	}
	for (; j < s.size(); j++) {
		if (it)
			continue;
		if (s[j] == ']' && !it) {
			i = j + 1;
			break;
		}

		if (s[j] == '[') {
			temp += dg(j + 1);
			it = true;
			continue;
		}
		if (it && s[j] == ']') {
			it = false;
			continue;
		}
		temp += s[j];
	}
	string t = temp;
	for (int j = 2; j <= add; j++)
		temp += t;
	return temp;
}

int main() {
	cin >> s;
	in = false;
	for (i = 0; i < s.size(); i++) {
		if (s[i] == '[') {
			in = true;
			cout << dg(i + 1);
			continue;
		}
		if (s[i] == ']') {
			in = false;
			continue;
		}
		if (in)
			continue;
		cout << s[i];
	}
	return 0;
}

为什么没过?下载数据也没发现问题,回必关。

2025/1/18 15:56
加载中...