标签:des style java color os strong
本题一开始我想用数组将数存起来,但想了好久就是没思路写下去,最后参考了人家的代码,写的挺不错的,和大家分享一下
3 2 4 2
3 6 3 7
思路:要用 cnt 来计数,计算和m相等;还要用 temp 来标记,控制是否输出空格
#include<stdio.h>
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
int temp=0,sum=0,i,cnt=0;
for(i=1;i<=n;i++)
{
sum+=2*i;//和写的挺不错的
cnt++;
if(cnt==m)
{
if(temp==0) temp=1;
else printf(" ");
printf("%d",sum/m);
sum=0;
cnt=0;
}
}
if(cnt!=0)
{
if(temp==0) temp=1;
else printf(" ");
printf("%d",sum/cnt);
}
printf("\n");
}
return 0;
}
标签:des style java color os strong
原文地址:http://blog.csdn.net/qq_16767427/article/details/38048039