中止陷阱:6错误

时间:2018-04-25 20:36:30

标签: c++

 #include <iostream>
 #define ll long long int
 using namespace std;

 int main()
 {
      ll t;
      cin >> t;
      ll res[t];
      for(ll k = 0; k < t; k++)
      {
           ll n, cnt = 0;
           ll arr[4] = {0};
           cin >> n;
           for(ll i = 0; i < (1<<n); i++)
           {
                ll x = 0;
                ll chk = 0;
                for(ll j = 0; j < n; j++)
                {
                     if(i & (1<<j))
                     {
                          chk++;
                          arr[x] = j+1;
                          x++;
                     }
                }
                if(chk == 2)
                {
                     if((arr[0] ^ arr[1]) <= n)
                          cnt++;
                }
           }
           res[k] = cnt;
           // cout << cnt << "\n";
      }
      for(ll i = 0; i < t; i++)
           cout << res[i] << "\n";
      return 0;
 }

程序在运行时崩溃。程序在某些测试用例中运行,但在打印结果后崩溃。在线编译器正在给出堆栈粉碎检测错误。我的计算机正在中止陷阱:终端上有6个错误。请帮忙。

1 个答案:

答案 0 :(得分:0)

数组arr [4]越界了。