AOJのシェルソートの問題を解いています。URLは下記です。
https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_D
次のプログラムは私の解答ですが、コンパイルエラーになります。VSCodeでは問題なく動きます。なぜエラーになるのでしょうか。
C++
1#include<iostream> 2using namespace std; 3 4int a[1000000]; 5 6void trace(int a[], int N) 7{ 8 for(int i=0; i<N; i++){ 9 if(i>0) cout << " "; 10 cout << a[i]; 11 } 12 cout << endl; 13} 14 15int main() 16{ 17 int N; 18 cin >> N; 19 int G[100]; 20 for(int i=0; i<N; i++) scanf("%d", &a[i]); 21 22 int h, count = 0, cnt = 0; 23 for(h=1; h<N; h=h*3+1) 24 ; 25 for( ; h>0; h/=3){ 26 if(h < N){ 27 G[count] = h; 28 count++; 29 } 30 for(int i=h; i<N; i++){ 31 int tmp = a[i]; 32 int j; 33 for(j=i-h; j>=0 && a[j]>tmp; j-=h){ 34 a[j+h] = a[j]; 35 cnt++; 36 } 37 a[j+h] = tmp; 38 } 39 } 40 41 cout << count << endl; 42 trace(G, count); 43 cout << cnt << endl; 44 for(int i=0; i<N; i++) 45 cout << a[i] << endl; 46 47 return 0; 48}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。