使用这种读入方式,MLE on #9,125MB
#include<bits/stdc++.h>
using namespace std;
string f() {
char x = getchar();
int k;
string s = "", rip = "";
while( x != '\n' ) {
if( x == '[' ) {
cin>> k;
rip = f();
while( k --> 0 )
s += rip;
}
else if( x == ']' ) return s;
else s += x;
x = getchar();
}
}
int main() {
cout<< f();
return 0;
}
然鹅,换成了这种,#9的内存空间变成了684KB?
#include<bits/stdc++.h>
using namespace std;
string f() {
char x;
int k;
string s = "", rip = "";
while( cin>> x ) {
if( x == '[' ) {
cin>> k;
rip = f();
while( k --> 0 )
s += rip;
}
else if( x == ']' ) return s;
else s += x;
}
}
int main() {
cout<< f();
return 0;
}
萌新不知道为什么,求大佬解答