解题思路:
还是for循环和标志变量的使用
注意事项:
参考代码:
要善于调适
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b,c,d;
int sum;
int n;
int arr[100];
int temp;
int temp1,temp2,temp3;
int i;
while(~scanf("%d %d",&a,&b))
{
//下
sum=0;
n=1;
temp=1;
while(a!=0)
{
if(a>=b)
{
temp2=b;
while(temp2!=0)
{
sum=sum+2+(n-1)*2;
temp2--;
n++;
}
arr[temp]=sum/b;
temp++;
sum=0;
a=a-b;
}
else
{
temp1=a%b;
temp3=temp1;
// printf("!!!!!!!!!!!!!!!!!!!!!!!!!\n");
while(0!=temp1)
{
sum=sum+2+(n-1)*2;
temp1--;
n++;
}
arr[temp]=sum/temp3;
temp++;
sum=0;
a=0;
}
}
// printf("!!!!!!!!!!!!!!!!!!!!!!!!!\n");
for( i=1;i<temp;i++)
{
if(i==temp-1)
{
printf("%d\n",arr[i]);
}
else {
printf("%d ",arr[i]);
}
}
}
return 0;
}
0.0分
0 人评分