出现这种结果可能是两种问题导致(目前我仅仅会知道两种,欢迎他人补充)的:
1、栈溢出,见下面的代码
#include<iostream>
#include<vector>
using namespace std;
vector<vector<char> >Graphs;
//vector<vector<bool> >visit;
int m = 0, n = 0 , q = 0 ;
int directx[4] = {-1,0,0,1};
int directy[4] = {0,-1,1,0};
struct direct2{
int x;
int y;
};
direct2 direction[4] = { (-1,0), (0,-1), (0,1), (1,0) };
int directionx[4] = {-1,0,0,1};
int directiony[4] = {0,-1,1,0};
void fill(int x, int y, char ch)
{
static int xx = 0, yy = 0;
Graphs[y][x] = ch;
for(int i = 0 ; i < 4; ++i)//DFS
{
// xx = x + directionx[i];
// yy = y + directiony[i];
xx = direction[i].x + x;
yy = direction[i].y + y;
if(xx >= 0 && xx < m && yy >= 0 && yy < n /*&& Graphs[yy][xx] != ch*/ && Graphs[yy][xx] != '|' &&
Graphs[yy][xx] != '-' && Graphs[yy][xx] != '+' )
{
fill(xx,yy,ch);
}
}
}
int main()
{
cin >> m >> n >> q;
Graphs.resize(n,vector<char>(m,'.'));
int sign=0, x1=0 , x2=0 , y1=0 , y2=0;
int x=0, y=0;
char ch = '0';
for(int i=1; i <= q; ++i)
{
cin >> sign;
if(sign == 0)
{
cin >> x1 >> y1 >> x2 >> y2;
// cin.get() ;
if(y1 == y2)
{
for(int j = min(x1,x2); j <= max(x1,x2); ++j)
{
if(Graphs[y1][j]== '.' || Graphs[y1][j]== '-')
{
Graphs[y1][j]= '-';
}
else if(Graphs[y1][j]== '|' || Graphs[y1][j] == '+')
{
Graphs[y1][j]= '+';
}
}
}
if(x1 == x2)
{
for(int j = min(y1,y2); j <= max(y1,y2); ++j)
{
if(Graphs[j][x1]== '.' || Graphs[j][x1]== '|')
{
Graphs[j][x1] = '|';
}
else if(Graphs[j][x1]= '-' || Graphs[j][x1] == '+')
{
Graphs[j][x1]= '+';
}
}
}
}
else if(sign == 1)
{
cin >> x >> y >> ch;
// cout << ch << endl;
fill(x,n-y-1,ch);
}
}
for(int i = 0; i < n; ++i )
{
for(int j = 0; j < m; ++j)
{
cout << Graphs[i][j];
}
cout << endl;
}
return 0;
}
上述代码中的fill()函数递归调用时,if判断条件中的判断Graphs[yy][xx] != ch这个判断注释掉之后,就会导致无穷递归,从而引起栈溢出,程序运行时会出现该问题(该题为CCF201512-3 画图,代码参考自:https://blog.csdn.net/wingrez/article/details/89047974。当时我自己写漏了这个条件,程序死活报标题中的结果,后来慢慢调试时才发现问题所在,把原代码放到VS中进行运行时就会提示:Stack overflow (参数: 0x00000001, 0x002C2F34)。0x00AAA5A7 处有未经处理的异常(在 CCFTTest.exe 中): 0xC00000FD: Stack overflow (参数: 0x00000001, 0x002C2F34)。话说真的很难理解这种比赛为什么还在用老掉牙的DevC++,运行时错误提醒真渣,但是还是得遵循:仗怎么打兵就怎么练,不然那习惯了VS的准确定位错误,上了认证机遇到了DevC++就傻眼了)
2、操作未未初始化的指针:比如,对一个未分配内存空间的指针进行赋值或者拷贝操作时,会出现这个问题。参见连接:https://zhidao.baidu.com/question/1960014709324954300.html
目前我就知道这两种情况会导致出现标题中的情况,若诸位大佬们知道有其他问题会导致这种现象的发生,欢迎补充,在此先谢过。