纯递归90分求教
查看原帖
纯递归90分求教
374180
pilgrimize楼主2021/2/8 16:39

第九个点MLE了,可以优化程序吗?

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string expand() {
	string s = "", X;
	char ch;int D;
	while ((ch = getchar())!='\n') {
		if (ch == '[') {			
			cin >> D;
			X = expand();
			while (D--) s += X;
		}
		else if (ch == ']') {
			return s;
		}
		else s += ch;
		//cout << s << endl;
	}
	return s;
}
int main() {
	cout << expand();
	
	return 0;
}

2021/2/8 16:39
加载中...