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?

Posted by 00448035 at 2005-03-20 14:12:44 on Problem 1016
#include <iostream.h>
#include <string.h>
#include <memory.h>


char later[100];
char * inventory(char previous[100])//检索函数,对一字符数组检索返回检索后的字符数组的头指针
{
	int b[10]={0};
	int c;
	char * array=later;
	for(int i=0;i<81;i++)//数字出现一次给以其为脚标的数组元素加1
	{
		if(previous[i]!='\0')
		{
			c=previous[i]-'0';
			++b[c];
		}
		else
			break;
	}
	for(i=0;i<10;i++)//顺序向数组中输入数字脚标元素值和数字
	{
		if(b[i]==0);
		else
		{
			if((b[i]/10)!=0)
			{
				*array=b[i]/10+'0';
				*(++array)=b[i]%10+'0';
				*(++array)=i+'0';
			}
			else
			{
				*array=b[i]+'0';
			    *(++array)=i+'0';
			}
			++array;
		}
	}
	return later;//返回检索后的数组的头指针
}
void main()
{
	char input[100];
	cin>>input;//输入第一例
    char (*results)[100];//放置原始值及历次检索值
	char n[100][100];//放置历次原始值
	int i;//计数器
	char result1[100][100];//放置计算结果对应的输出语言
	int result2[100];//放置计算结果对应的输出数字
	int j,symbol,k=0;//计数器及标志
    int min;//最小步长
	while(strcmp(input,"-1"))//判断输入结束(新一例从此开始)
	{
		symbol=0;
		strcpy(n[k],input);//存储原始值
		results=new char[16][100];//新建一二维数组
		strcpy(results[0],input);//存入原始值
	    for(i=1;i<16;i++)//顺序存入历次检索值
		{
			strcpy(results[i],inventory(results[i-1]));
		}
		if(!strcmp(results[0],results[1]))//比较数组头两个元素是否相同,若相同则为自检索
		{
			strcpy(result1[k]," is self-inventorying");
			result2[k]=0;
		    symbol=1;
		}
		else//若不同
		{
			for(i=1;i<15;i++)
			{
				if(!strcmp(results[i],results[i+1]))//比较数组各相邻两项是否相同,若相同则为间接检索
				{
					strcpy(result1[k]," is self-inventorying after ");
					result2[k]=i;
					symbol=1;
					break;
				}

			}
            if(symbol==0)
           {
            min=15;
			for(i=0;i<14;i++)//若相邻两项均不同
			{
				for(j=i+2;j<16;j++)
				{
					if(!strcmp(results[i],results[j]))//若出现后项与前项相同则为变异自检索
					{
                        strcpy(result1[k]," enters an inventory loop of length ");
                        if(j-i<=min)
                        min=j-i;
						
						symbol=-1;
						
					}
					
				}
				
			}
            if(symbol==-1)
            result2[k]=min;
           }

		}
		if(symbol==0)//若上述情况均没出现则为不可归类
		{
			strcpy(result1[k]," can not be classified after 15 iterations");
			result2[k]=0;
		}
		++k;
		cin>>input;//下一例输入
		delete []results;
		memset(later,'\0',100);
	}
	for(i=0;i<k;i++)//顺序输出各例结果
	{
		if(result2[i]==0)
		cout<<n[i]<<result1[i]<<endl;
		else
		{
			if(strcmp(result1[i]," enters an inventory loop of length "))
				cout<<n[i]<<result1[i]<<result2[i]<<" steps"<<endl;
			else
				cout<<n[i]<<result1[i]<<result2[i]<<endl;
		}
	}
}







	    

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