POJ 1016 Numbers That Count G++
程序员文章站
2022-03-05 12:58:17
...
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string myhs(string x)
{
string y;
y.reserve(100);
for(int i=0;i<10;i++)
{
int js=0;
for(int j=0;j<x.size();j++)
{
if(x[j]==(char)(i+'0'))
{
js++;
}
}
if(js>0)
{
if(js>9)
{
y=y+(char)(js/10+'0');
y=y+(char)(js%10+'0');
}else
{
y=y+(char)(js+'0');
}
y=y+(char)(i+'0');
}
}
return y;
}
int main()
{
while(1)
{
string a;
cin>>a;
if(a=="-1")
{
break;
}
vector<string> jl;
string qian;
qian.reserve(100);
qian=a;
int ff=0;
for(int i=0;i<15;i++)
{
jl.push_back(qian);
string t;
t.reserve(100);
t=myhs(qian);
//cout<<t<<endl;
if((t==a)&&(i==0))
{
ff=1;
cout<<a<<" is self-inventorying"<<endl;
break;
}else if(t==qian)
{
ff=1;
cout<<a<<" is self-inventorying after "<<i<<" steps"<<endl;
break;
}else
{
int flag=0;
for(int j=0;j<jl.size();j++)
{
//cout<<"//"<<jl[j]<<endl;
if(t==jl[j])
{
flag=1;
ff=1;
cout<<a<<" enters an inventory loop of length "<<jl.size()-j<<endl;
break;
}
}
if(flag==1)
{
break;
}
}
//qian.reserve(200);
qian=t;
}
if(ff==0)
{
cout<<a<<" can not be classified after 15 iterations"<<endl;//谢谢博友程序
}
}
return 0;
}
标牌公司。5553141由2个1、1个3、1个4和3个5组成,记做21131435。例如。31123314记做31123314。314213241519记做412223241519;412223241519记做314213241519。