杭电acm2015题,结果对,为什么递交不上?

2024-12-04 10:38:56
推荐回答(1个)
回答(1):

将sanf("%d%d",&n,&m);去掉,在a[0]=2;上面加一行while(scanf("%d%d",&n,&m)!=EOF)就行啦
改完后的程序就是
#include
int main()
{
int i,a[100],n,m,j,k,s,h,u,l;
while(scanf("%d%d",&n,&m)!=EOF)
{
a[0]=2;
for(i=1;i a[i]=a[i-1]+2;

k=0;h=n-m;u=n/m;l=n%m;
if(l==0)
{
for(j=0;j {
s=0;
for(i=j*m;i s=s+a[i];
k=k+1;
if(k==1)
printf("%d",s/m);
else
printf(" %d",s/m);
}
}
if(h>=0&&l!=0)
{
for(j=0;j {
s=0;
for(i=j*m;i s=s+a[i];
k=k+1;
if(k==1)
printf("%d",s/m);
else
printf(" %d",s/m);
}
s=0;
for(i=n-l;i s=s+a[i];
printf(" %d",s/l);
}
if(h<0)
{
s=0;
for(i=0;i s=s+a[i];
printf("%d",s/n);
}
printf("\n");
}
return 0;
}
因为题目提到了“输入数据有多组,每组占一行,包含两个正整数n和m,n和m的含义如上所述。”说明测试数据要用循环输入所以在while语句中加scanf输入