Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:哪里出问题了,帮帮忙呀,我实在是找不出来啦!!!!!

Posted by Dawnee at 2010-11-10 15:14:48 on Problem 2017
In Reply To:哪里出问题了,帮帮忙呀,我实在是找不出来啦!!!!! Posted by:00430030 at 2005-01-10 16:20:37
> #include<stdio.h>
> #include<math.h>
> void main ()
> {
>     int  n,a[20],b[20],i,sum=0,j;
> 	for(;;)	
> {	scanf("%d",&n);
>     if(n==-1)  goto end;    
> 	for(i=0;i<n;i++)
> 			scanf("%d %d",&a[i],&b[i]);
> 	
> 		if(n==1)  printf("%d miles\n",a[0]*b[0]);
> 		else  
> {       sum=0;
> 		for(j=1;j<n;j++)    
> 		sum=sum+a[0]*b[0]+a[j]*(b[j]-b[j-1]);
> 		printf("%d miles\n",sum);
> 	}
> end:;
> }
> }
首先你的end:位置错了,应在for语句外面
其次,sum=sum+a[0]*b[0]+a[j]*(b[j]-b[j-1]);这样会重复计算a[0]*b[0]的。

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator