AC代码
#include <bits/stdc++.h>
using namespace std;
string read(){
char c;
int d;
string s, sp;
while(cin>>c){
if(c == '['){
scanf("%d", &d);
sp = read();
while(d--) s += sp;
}
else{
if(c == ']') return s;
else s+=c;
}
}
}
int main()
{
cout << read();
return 0;
}
MLE代码
#include <bits/stdc++.h>
using namespace std;
char c;
int d;
string read(){
string s, sp;
while(cin>>c){
if(c == '['){
scanf("%d", &d);
sp = read();
while(d--) s += sp;
}
else{
if(c == ']') return s;
else s+=c;
}
}
}
int main()
{
cout << read();
return 0;
}
差别就在变量D和字符C定义在read()外面
请问大佬为什么出现这种现象?