杭电ACM2015题我哪里错了?在电脑上调试对的;

2024-11-27 01:38:26
推荐回答(2个)
回答1:

数组建议定义的大一点,防止越界,输出格式错误,每行末尾多一个空格,输出结果转换成int型
下面是修改过的

#include"stdio.h"
int main()
{
int n,m,j,i,a[1000],t,h,b,c;
float sum,awer[1000];
while(scanf("%d %d",&n,&m)!=EOF&&n<=100&&n>0&&m>0&&m<=100)
{ b=0;
if(m>n)
{
t=m;
m=n;
n=t;
}
c=n/m;
for(i=0;i<=c;i++)
{
sum=0;
if(n-(i*m)>=m)
{h=m*(i+1);}
else
{h=h+(n%m);}
for(j=i*m;j {

b=b+1;
a[j]=2*b;
sum=sum+a[j];
}
if(n-(i*m)>=m)
{awer[i]=sum/m;}
else
{awer[i]=sum/(n%m);}

}
if(n%m==0)
{
for(i=0;i {
printf("%d ",(int)awer[i]);
}
}
if(i==c-1)
printf("%d",(int)awer[i]);
else
{
for(i=0;i {
printf("%d ",(int)awer[i]);
}
}
if(i==c)
printf("%d",(int)awer[i]);
printf("\n");
}
return 0;
}

回答2:

你怎么输出的是浮点啊?
#include
main()
{
int m,n,sum,p,i,term;
while(scanf("%d %d",&n,&m)!=EOF)
{
i=1;
p=1;
sum=0;
while(n>0)
{
sum=0;
if(n>m)
{
for(i=p;i {
sum+=2*i;
}
p=i;
printf("%d ",sum/m);
n-=m;
}
else
{
p=i;
for(i=p;i {
sum+=2*i;
}
printf("%d",sum/n);
n=0;
}
}
printf("\n");
}
}