CCF-(201703-1)分蛋糕-C语言(100分)

在这里插入图片描述在这里插入图片描述
一道比较简单的题目,一边获得蛋糕重量的输入,一边对蛋糕重量达到k进行处理即可

#include <stdio.h>

int main(){
   int n,k,i,num=0,cake=0;
   scanf("%d%d",&n,&k);
   int *a;
   a=(int *)calloc(n,sizeof(int));
   for(i=0;i<n;i++){
       scanf("%d",&a[i]);
       cake+=a[i];
       if(cake>=k){
           cake=0;
           num++;
       }
   }
   if(cake!=0)
      num++;
   printf("%d",num);
   return 0;
}
发布了33 篇原创文章 · 获赞 11 · 访问量 8455

猜你喜欢

转载自blog.csdn.net/qq_40825479/article/details/105581003