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:那位高手帮忙看一看1017题!为什么是Runtime Error

Posted by hawk at 2004-01-01 21:08:24
In Reply To:那位高手帮忙看一看1017题!为什么是Runtime Error Posted by:jiang at 2004-01-01 20:23:15
> #include<stdio.h>
> #include<math.h>
> 
> void main()
> {
> 	int xi[6],num[20];

没人告诉你只有20组数据,一旦数据超过20,就数组越界,当然会RE
输入和输出是不相干的,你可以算出一个就输出一个,没必要保存到最后输出。
> 	int i=0,j=0,k=0,sa=0;
> 	for(j=0;j<6;j++)scanf("%d",&xi[j]);
>     while(xi[0]+xi[1]+xi[2]+xi[3]+xi[4]+xi[5]) 
> 	{   
> 		num[i]=xi[5]+xi[4]+xi[3]+xi[2]/4;
> 		xi[2]=xi[2]%4;
> 		k=(4-xi[2])*2-1;
> 		sa=xi[1];
> 		xi[1]=xi[1]-5*xi[3]-k;
> 		if(xi[1]<0)
> 		{
> 			xi[1]=0;
> 			xi[0]=xi[0]-xi[3]*20+sa*4;
> 		}
> 		xi[0]=xi[0]-11*xi[4]-(36-9*xi[2]-4*k);
> 	    if(xi[0]<0)xi[0]=0;
> 	    if(xi[2]>0)num[i]++;
> 		k=(xi[0]+xi[1]*4)%36;
> 		num[i]=num[i]+(xi[0]+xi[1]*4)/36;
> 		if(k!=0)num[i]++;
> 		i++;
> 		for(j=0;j<6;j++)scanf("%d",&xi[j]);
> 	    }
> 	for(j=0;j<i;j++)printf("%d\n",num[j]);
> }
> 			

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