杭电ACM1001题(新手求高手解答谢谢!!)
为什么第一种算法ac了,而第二种算法ac不了,wronganswer1:#include<stdio.h>intmain(){inti,n,sum=0;while(sca...
为什么第一种算法ac了,而第二种算法ac不了,wrong answer
1:#include<stdio.h>
int main()
{
int i,n,sum=0;
while(scanf("%d",&n)!=EOF)
{
for(i=1;i<=n;i++)
sum=sum+i;
printf("%d\n\n",sum);
sum=0;
}
return(0);
}
:2:
#include<stdio.h>
int main()
{
long long int n,sum;
while(scanf("%lld",&n)!=EOF)
{
sum=(1+n)*n/2;
printf("%I64d\n",sum);
printf("\n");
}
return(0);
} 展开
1:#include<stdio.h>
int main()
{
int i,n,sum=0;
while(scanf("%d",&n)!=EOF)
{
for(i=1;i<=n;i++)
sum=sum+i;
printf("%d\n\n",sum);
sum=0;
}
return(0);
}
:2:
#include<stdio.h>
int main()
{
long long int n,sum;
while(scanf("%lld",&n)!=EOF)
{
sum=(1+n)*n/2;
printf("%I64d\n",sum);
printf("\n");
}
return(0);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询