0x003B8027 处有未经处理的异常(在*.exe 中): 0xC00000FD: Stack overflow (参数: 0x00000000, 0x00252000)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zzq060143/article/details/78198217

如图,错误信息如下:


代码如下所示,找了半天错误还以为自己代码有问题,然而并不是,真是心累。。。

#include "myfun.h"
#include <iostream>
#include <algorithm>
#include <utility>

const int MAX_N = 1000000;

using namespace std;

//区间调度问题
//s:任务开始时间
//e:任务结束时间
//N:任务数量
int solve(int s[], int e[], int N)
{
	pair<int, int> mCache[MAX_N];
	int ans = 0, cunTime = 0;
	for (int i = 0; i < N; i++)
	{
		mCache[i].first = e[i];
		mCache[i].second = s[i];
	}
	sort(mCache, mCache + N);
	for (int i = 0; i < N; i++)
	{
		if (cunTime < mCache[i].second)
		{
			ans++;
			cunTime = mCache[i].first;
		}
	}
	return ans;
}

int main()
{
	int n, s[MAX_N], e[MAX_N];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> s[i];
	}
	for (int i = 0; i < n; i++)
	{
		cin >> e[i];
	}
	int ans = solve(s, e, n);
	cout << ans << endl;
	system("pause");
	return 0;
}

解决方法:

按照错误提示我们可以知道该错误是“栈溢出”,回头一看可能出错的地方也就是在定义数组的地方了,当把预定义的数组大小改成10000之后,程序居然可以运行了,由此看来是我们定义的数组太大了,所以在定义数组的时候一定要谨记千万别太大,如果非要用容量比较大的数组的话建议可以使用new进行分配,然后在函数返回时记得delete就行了。


猜你喜欢

转载自blog.csdn.net/zzq060143/article/details/78198217