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

怎么一直是runtime error,路过的人有空帮我看看这段程序哦,不胜感激,我改了n次了都

Posted by pandy at 2009-02-16 14:32:12 on Problem 3195
#include<stdio.h>
#include<math.h>
int flag;
char num[12],str[100000002];
int a[100002],n;
void input()
{
	int i,p;
	n=0;p=0;
	for(i=0;(num[i]=str[p])!='\n';i++,p++){
		if(num[i]==' '){
			num[i]='\0';
			sscanf(num,"%d",&a[n++]);
			i=-1;
		}
	}
	if(i>0){
		num[i]='\0';
		sscanf(num,"%d",&a[n++]);
	}
}
void process(int begin,int end)
{
	int sum,index,i,j;
	if(a[begin]+a[end]!=0||a[begin]>=0||flag==0){
		flag=0;return;
	}
	if(begin+1>=end)
		return ;
	sum=0;index=begin+1;
	for(i=begin+2;i<end;i++){
		if(a[index]+a[i]==0){
			sum+=abs(a[i]);
			process(index,i);
			index=i+1;
			i++;
		}
	}
	if(i==end){
		flag=0;return ;
	}
	if(sum>=abs(a[begin])){
		flag=0;return ;
	}

}
int main()
{
	int i;
	while(gets(str)!=NULL){
		input();
		flag=1;
		process(0,n-1);
		if(flag)
			printf(":-) Matrioshka!\n");
		else
			printf(":-( Try again.\n");
	}
}

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