program.exe停止处理大输入



这是我的代码

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
#include<bitset>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<queue>
using namespace std;
int d1[] = { 0,0,1,-1,1,-1 ,1,-1 };
int d2[] = { -1,1,0,0,1 ,-1,-1,1 };
string vec[200 + 5];
int counter = 0;
long long int floodfill(int n1, int n2, char c1, char c2,int ss)
{
    if (n1 < 0 || n1 >= ss || n2 < 0||n2>=vec[n1].length())
        return 0;
    if (vec[n1][n2] != c1) return 0;
    long long int ans = 1;
    vec[n1][n2] = c2;
    for (int i = 0; i < 8; i++)
        ans = ans + floodfill(n1 + d2[i], n2 + d1[i], c1, c2,ss);
    return ans;
}
int floodfill2(int n1, int n2, char c1, char c2,int ss)
{
    if (n1 < 0 || n1 >= ss || n2 < 0 || n2 >= vec[n1].length())
        return 0;
    if (vec[n1][n2] == '0')
    {
        floodfill(n1, n2, '0', c1,ss);
        counter++;
    }
    if (vec[n1][n2] !=c1) return 0;
    int ans = 1;
    vec[n1][n2] = c2;
    for (int i = 0; i < 4; i++)
        ans = ans + floodfill2(n1 + d1[i], n2 + d2[i], c1, c2,ss);
    return ans;
}
int main() {
    int n1;
    int n2;
    int co = 1;
    while (true)
    {
        cin >> n1;
        cin >> n2;
        if (n1 == 0 && n2 == 0)
            break;
        getchar();
        int aa = 0;
        for (int i = 0; i < n1; i++)
        {
            char s[300];
            scanf("%s", s);
            string g = "";
            int a = strlen(s);
            for (int j = 0; j <a; j++)
            {
                string temp = "";
                if (s[j] == '0')
                    temp = "0000";
                else if (s[j] == '1')
                    temp = "0001";
                else if (s[j] == '2')
                    temp = "0010";
                else if (s[j] == '3')
                    temp = "0011";
                else if (s[j] == '4')
                    temp = "0100";
                else if (s[j] == '5')
                    temp = "0101";
                else if (s[j] == '6')
                    temp = "0110";
                else if (s[j] == '7')
                    temp = "0111";
                else if (s[j] == '8')
                    temp = "1000";
                else if (s[j] == '9')
                    temp = "1001";
                else if (s[j] == 'a')
                    temp = "1010";
                else if (s[j] == 'b')
                    temp = "1011";
                else if (s[j] == 'c')
                    temp = "1100";
                else if (s[j] == 'd')
                    temp = "1101";
                else if (s[j] == 'e')
                    temp = "1110";
                else if (s[j] == 'f')
                    temp = "1111";
                g =g+ temp;
            }
            vec[aa] = g;
            aa++;
        }
        floodfill(0, 0, '0', '.',aa);
        string ans = "";
        for (int i = 0; i < aa; i++)
        {
            for (int j = 0; j < vec[0].length(); j++)
            {
                counter = 0;
                if (vec[i][j] == '1')
                {
                    floodfill2(i, j, '1', '.',aa);
                    if (counter == 0)
                        ans = ans + 'W';
                    else if (counter == 1)
                        ans = ans + 'A';
                    else if (counter == 2)
                        ans = ans + 'K';
                    else if (counter == 3)
                        ans = ans + 'J';
                    else if (counter == 4)
                        ans = ans + 'S';
                    else if (counter == 5)
                        ans = ans + 'D';
                }
            }
        }
        sort(ans.begin(), ans.end());
        cout << "Case " << co  << ": " << ans << endl;
        co++;
    }
}

它在这个输入上工作

6 25
0000000000000000000000000
0000000000000000000000000
00001fe0000000000007c0000
00003fe0000000000007c0000
0000000000000000000000000
0000000000000000000000000

但是停止了对这个的工作

200 50
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000

您有以下代码:

string vec[200 + 5];
...
if (vec[n1][n2] != c1) return 0;

我看不出你在检查这个数组是否永远不会越界,即代码是否试图访问大于205的元素。

我预计,随着你的大量投入,你将失去债券。

一种简单的检查方法是运行调试构建。一个好的调试c运行库应该会给你一个显式的越界错误。

否则,您可以添加以下内容:

#define MAXSIZE 204
string vec[ MAXSIZE];
...
if( n1 >= MAXSIZE )
{
   cout << "ERROR: Input too bign";
   exit(1);
}

最新更新