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

Help:Runtime Error多谢

Posted by IC0590501120 at 2005-12-22 09:39:33 on Problem 1017
虽然程序编的比较龌龊,但自己测验是对的。提交时总显示Runtime Error,求助。
不胜感激。

#include<stdio.h>
int q2(int a){//给出3*3后剩余的位置数,求出2*2可放多少
	int key;
	switch(a){
		case 1:key=1;break;
		case 2:key=3;break;
		case 3:key=5;break;
		case 4:key=0;break;
	}return key;
}
int q1(int a,int b){//给出剩余的1*1位置数b,求出是否需要多加箱子
	int n,c,j;
	if (a>b){
		n=(a-b);
		j=n%36;
		if (j=0) c=n/36;
		else c=n/36+1;}
	else c=0;
	return c;
}
int num(int a,int b,int c,int d,int e,int f){
	int number[6];
	int z,i,j,p,q,n;
	number[5]=f;//6*6
	number[4]=e;//5*5
	number[3]=d;//4*4
	j=c/4;i=c%4;
	if(i==0)number[2]=j;
	else number[2]=j+1;//3*3没放满时
	p=number[3]*5+q2(4-i);//p:2*2可放的位置数 i=0?让i不等于0
		if(p>=b)//当无需为了2*2多增加箱子时
			{number[1]=0;
			if((number[3]*5)>b)//4*4的已经足够了
				q=number[4]*11+(number[3]*5-b)*4+9*(4-i);//q:可放1*1位置数(5*5+4*4+3*3)
			else q=number[4]*11+9*(4-i)-4*(b-number[3]*5);//q:5*5+3*3中还可放的数目
			number[0]=q1(a,q);
		}
		else//处理需要为2*2多加箱子的情况
			{q=b-p;
			n=q%9;//q是多出的2*2箱子的数目
			if(n==0) {number[1]=q/9;j=number[4]*11+(4-i)*9-q2(4-i)*4;}
			else {number[1]=q/9+1;//求出为了2*2而多加的箱子数
			j=number[4]*11+(4-i)*9-q2(4-i)*4+(9-n)*4;}//j:可放1*1的位置数
			number[0]=q1(a,j);
		}
	z=0;
	for(i=0;i<6;i++)
		z=z+number[i];
	return z;
}
void main(){
	int sum[10];
	int a,b,c,d,e,f,i=0,j;
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
	do{sum[i]=num(a,b,c,d,e,f);
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
	i++;}while(a+b+c+d+e+f!=0);
	for(j=0;j<i;j++)
		printf("%d\n",sum[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