#9229: 請問一下


hugo8642612 (Hugowwwwwww)


 看了好幾遍
提交之後都是記憶體區段錯誤
可是東西都有好好的裝在陣列裡面 究竟是哪裡的東西跑出來了
請大大幫忙看看一下
tail是尾巴的位置
head是頭的位置 
all是紀錄加總 
 
#include<stdio.h>
int main(){
int n;
while(scanf("%d",&n)!=-1){
int a[100001];
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
int all=0;
int count=0;
int head=0;
int tail=n-1;
while(1){
if(all>0){
all-=a[tail];
tail-=1;
}
else{
all+=a[head];
head+=1;
}
if(all==0)
count+=1;
if(head==n-1 && tail==0)
break;
}
printf("%d\n",count+1);
}