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:贴下代码 一次ac

Posted by 1512335532 at 2015-07-20 10:26:57 on Problem 1016
In Reply To:贴下代码 一次ac Posted by:ooglmxx at 2011-10-03 20:03:47
> #include <iostream>
> #include <string>
> #include <vector>
> using namespace std;
> 
> unsigned getLength(vector<string>& vps)
> {
> 	unsigned length=1;
> 	for(unsigned pos=2; pos<vps.size(); ++pos)
> 	{
> 		for(length=1; length<=pos; ++length)
> 			if(vps[pos-length]==vps[pos])
> 				return length;
> 	}
> 	return 0;
> }
> 
> int main()
> {
> 	string n, vnp, vnq;
> 	vnp.reserve(100), vnq.reserve(100);   //最长给出的字符串不会超过80个
> 	vector<int> note;      //用于记录下一次字符串的形态
> 	vector<string> vps;   //记录每次转换的字符串形态
> 	
> 	while(cin>>n, n!="-1")
> 	{
> 		vps.clear();
> 		vnp=n, vnq=vnp;
> 		int iterations=0, steps=0, length=0;
> 		while(iterations!=15)
> 		{
> 			vnq=vnp;
> 			note.assign(20, 0);   //记录下次转换的字符串形态
> 			for(string::size_type i=0; i<vnp.size(); ++i)
> 			{
> 				int idx=vnp[i]-'0';
> 				note[idx]++;
> 			}
> 			vnp.clear();
> 			for(int idx=0; idx<10; ++idx)
> 			{
> 				if(note[idx]==0)
> 					continue;
> 				if(note[idx]>=10 )
> 				{
> 					char c1=note[idx]/10+'0', c2=note[idx]%10+'0';
> 					vnp.push_back(c1);
> 					vnp.push_back(c2);
> 				}
> 				else
> 					vnp.push_back(note[idx]+'0');
> 				vnp.push_back(idx+'0');
> 			}
> 			++steps;
> 			if(vnp==vnq)
> 				break;
> 			vps.push_back(vnp);
> 			if(length=(int)getLength(vps))
> 				break;
> 			++iterations;
> 		}
> 		if(steps==1)
> 			cout<<n<<" is self-inventorying"<<endl;
> 		else if(iterations==15)
> 			cout<<n<<" can not be classified after 15 iterations"<<endl;
> 		else if(vnp==vnq)
> 			cout<<n<<" is self-inventorying after "<<steps-1<<" steps"<<endl;
> 		else
> 			cout<<n<<" enters an inventory loop of length "<<length<<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