为什么变量定义在函数外会MLE?
查看原帖
为什么变量定义在函数外会MLE?
247202
OnlyExtreme楼主2021/7/6 11:49

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()外面 请问大佬为什么出现这种现象?

2021/7/6 11:49
加载中...