为什么CodeChef在线ide在其他在线ide上完美运行的同时,也跟随插入排序而给出SIGSEGV错误?]

问题描述 投票:0回答:1
在其他在线ide上运行,但不在CodeChef ide上运行。我不明白为什么会这样。如何在CodeChef ide上运行它?

#include <bits/stdc++.h> #define REP(i,a,b) for(i=a;i<=b;i++) using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); int tt; int array [tt]; int key; int i; int p; cin >> tt; REP(i,1,tt) cin >> array[i-1]; REP(i,1,tt-1){ key = array[i]; p = i-1; while(p>=0 && array[p]>key){ array[p+1]=array[p]; p--; } array[p+1] = key; } REP(i,1,tt) cout << array[i-1] << " "; }

在其他在线ide上运行,但不在CodeChef ide上运行。我不明白为什么会这样。如何在CodeChef ide上运行它? #include 

#为(...]定义REP(i,a,b)(...

c++ segmentation-fault insertion-sort
1个回答
0
投票
没有问题。发现我的错误。我应该在声明数组之前使用cin >> tt。我想这是一个垃圾值,我认为数组超出了范围。
© www.soinside.com 2019 - 2024. All rights reserved.