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 wcfairytale at 2007-02-15 15:30:33 on Problem 1016
#include<iostream>
#include<string>
#include<vector>

using namespace std;

vector<string> s(17);

int main()
{
	int K,L,M;
	int p;
	while(cin>>s[0])
	{
		if(s[0]=="-1")break;
		L=0;
		while(L<16)
		{
			p=1;
			int num[10]={0};//纪录各数字个数
			//纪录数字0~9分别有多少个
			for(K=0;s[L][K];++K)
			{
				num[s[L][K]-'0']++;
			}
			M=0;
			++L;
			s[L]=s[L-1];//给相同长度
			//生成s[L+1]
			for(K=0;K<10;++K)
			{
				if(num[K]!=0)
				{
					s[L][M++]=num[K]+'0';
					s[L][M++]=K+'0';
				}
			}
			//cout<<s[1]<<'\n'<<s[2]<<'\n'<<endl;
			//self-inventorying情况
			if(s[1]==s[0] )
			{
				cout<<s[0]<<" is self-inventorying"<<endl;
				break;
			}
			//is self-inventorying after ... steps情况
			else if(s[L]==s[L-1])
			{
				cout<<s[0]<<" is self-inventorying after "<<L-1<<" steps"<<endl;
				break;
			}
			//enters an inventory loop of lenth...情况
			else
			{
				for(K=0;K<L;++K)
				{
					if(s[L]==s[K])
					{
						cout<<s[0]<<" enters an inventory loop of length "
							<<L-K<<endl;
						p=0;
						break;
					}
				}
			}
			if(p==0)break;
		}
		//15次后仍无解的情况
		if(L==16)cout<<s[0]<<" can not be classified after 15 iterations"<<endl;
	}
	return 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