#include <stdio.h>
#include <string.h>
int x,y,z,w;
int n; // poison
int rbtWght;
int rabbitFate(int eatIntArr[100],int days){
int isPoison = 0;// poisoning
int isDead = 0;
int po = 0;
int i;
for(i = 0; i < days; i++){
if (isPoison){
rbtWght -= po;
}
if (rbtWght <= 0){
isDead = 1;
break;
}
switch (eatIntArr[i]){
case 1:
rbtWght += x;
break;
case 2:
rbtWght += y;
break;
case 3:
rbtWght -= z;
break;
case 4:
rbtWght -= w;
po += n;
isPoison = 1;
break;
}
}
if (isDead){
printf("bye~Rabbit\n");
// return isDead;
}else{
printf("%dg\n", rbtWght);
// return isDead;
}
}
int main(void){
int t;
int eat;
char el;
int eatIntArr[100];
int i;
scanf("%d",&t);
while(t--){
scanf("%d %d %d %d %d %d",&x,&y,&z,&w,&n,&rbtWght);
i = 0;
for(i = 0,el = ' '; el != '\n'; i++){
scanf("%d%c",&eat,&el);
eatIntArr[i] = eat;
}
rabbitFate(eatIntArr,i);
memset(eatIntArr,0,sizeof(eatIntArr));
}
return 0;
}
請問一下
記憶體區段錯誤,是指我的陣列不夠大嗎
還是說有其他問題我沒有注意到...?