小明种苹果(续)

经过上次的错误,有了经验。终于解决了这个问题。

#include<cstdio>
#include<cstdlib>
#include<cstring>
int main()
{
    int n;
    int count=0;             //drop apple tree count
    int temp=0;             //operation sum
    int sum=0;              //apple sum
    scanf("%d",&n);
    bool a[n];              //status change
    int reserve,change;
    int continuoustree=0;  // three continuous count

    for(int i=0;i<n;i++){
        a[i]=false;
        reserve=0;
        scanf("%d",&temp);
        for(int j=0;j<temp;j++){
            scanf("%d",&change);
            if(j==0){
                reserve=change;
            }else{
                if(change>0){
                    if(reserve!=change){
                        a[i]=true;
                    }
                    reserve=change;

                }else{
                    reserve+=change;
                }
            }
        }
        sum+=reserve;
        if(a[i]){
            count++;
        }
    }
    for(int i=0;i<n;i++){
        if(a[i]&&a[i-1<0?(n-1):(i-1)]&&a[i+1>(n-1)?0:(i+1)]){
            continuoustree++;
        }
    }
    printf("%d %d %d",sum,count,continuoustree);


}

奥里给,加油!
 

相关文章: