-2
#include<stdio.h>
int arr[12][5];
int score[12][5];
int n;
void chk(){
int score = 0;
for(int i=n-1;i>=0;i--){
for(int j = 0;j<5;j++){
scanf("%d",&(arr[i][j]));
}
}
for(int i = n-1;i>=0;i--){
for(int j=0;j<5;j++){
if(i==n-1)
score[i][j] = arr[i][j];
else{
int mx = score[i+1][j];
if(j>0 && score[i+1][j-1]>mx)
mx = score[i+1][j-1];
else if(j<4 && score[i+1][j+1]>mx)
mx = score[i+1][j-1];
score[i][j] = arr[i][j] + mx;
}
}
}
int mx_score = score[0][2];
if(score[0][1]>mx_score){
mx_score = score[0][1];
}
else if(score[0][3]>mx_score){
mx_score = score[0][3];
}
printf("%d",mx_score);
}
int main(){
int T;
scanf("%d",&T);
for(int i = 0;i<T;i++){
scanf("%d",&n);
chk(n);
}
return 0;
}
コンパイルエラー:このコードはなぜコンパイルエラーになりますか? [C、グローバル変数、2Dアレイ]
Subscripted value is not an array, pointer or vector.
エラーがscore
ある原因変数。 なぜarr
がうまく動作するのか分かりませんが、score
はありません。 このコードをどのように書きますか?
インデントは適切に私はあなたがscore
を再宣言
コードを改善する方法の1つは、適切にインデントすることです。 –
このことについて申し訳ありません。 – 4words
追加情報を提供するための質問に対して[編集]することをお勧めします。すでに投稿されている回答を無効にするために十分に質問を変更する編集は許可されていません。実際、[編集権](http://stackoverflow.com/help/privileges/edit)を持つユーザは、そのような編集を元に戻すべきであるというコンセンサスがあります。このコメントを投稿した直後に私はそうするでしょう。これは、回答が投稿される前に質問を完全に変更することを妨げるものではありません。新しい問題については[新しい質問](http://stackoverflow.com/questions/ask)にお答えできます。 – Makyen