poj1016
来源:互联网 发布:知乎 管理者 编辑:程序博客网 时间:2024/05/22 16:05
#include<iostream>
#include<string>
using namespace std;
string record[16] = {""};
string num;
int main()
{
cin >> num;
while (num != "-1")
{
int cha = 0;
int sta = 0;
record[0] = num;
for(int i=0;i<15;i++)
{
int length = 0;
while(record[i][length]!='\0')
length++;
int array[10] = { 0 };
for(int j=0;j<length;j++)
{
int mark = record[i][j] - '0';
array[mark]++;
}
string temp = "";
for(int j=0;j<10;j++)
{
if(array[j]!=0)
{
string geshu="", shu="";
if (array[j] < 10)
geshu = array[j] + '0';
else
{
geshu = array[j]/10 + '0';
geshu += (array[j] % 10) + '0';
}
shu = j + '0';
temp += geshu;
temp += shu;
}
}
record[i+1] = temp;
for(int j=0;j<=i;j++)
{
if(record[j]==temp)
{
cha = i + 1 - j;
sta = j;
break;
}
}
if(cha==1)
{
if (sta == 0)
{
cout << num << " is self-inventorying" << endl;
}
else cout << num << " is self-inventorying after " << sta << " steps" << endl;
break;
}
else if(cha!=0)
{
cout << num << " enters an inventory loop of length " << cha<<endl;
break;
}
}
if (cha == 0)
cout << num << " can not be classified after 15 iterations" << endl;
cin >> num;
}
return 0;
}
#include<string>
using namespace std;
string record[16] = {""};
string num;
int main()
{
cin >> num;
while (num != "-1")
{
int cha = 0;
int sta = 0;
record[0] = num;
for(int i=0;i<15;i++)
{
int length = 0;
while(record[i][length]!='\0')
length++;
int array[10] = { 0 };
for(int j=0;j<length;j++)
{
int mark = record[i][j] - '0';
array[mark]++;
}
string temp = "";
for(int j=0;j<10;j++)
{
if(array[j]!=0)
{
string geshu="", shu="";
if (array[j] < 10)
geshu = array[j] + '0';
else
{
geshu = array[j]/10 + '0';
geshu += (array[j] % 10) + '0';
}
shu = j + '0';
temp += geshu;
temp += shu;
}
}
record[i+1] = temp;
for(int j=0;j<=i;j++)
{
if(record[j]==temp)
{
cha = i + 1 - j;
sta = j;
break;
}
}
if(cha==1)
{
if (sta == 0)
{
cout << num << " is self-inventorying" << endl;
}
else cout << num << " is self-inventorying after " << sta << " steps" << endl;
break;
}
else if(cha!=0)
{
cout << num << " enters an inventory loop of length " << cha<<endl;
break;
}
}
if (cha == 0)
cout << num << " can not be classified after 15 iterations" << endl;
cin >> num;
}
return 0;
}
阅读全文
1 0
- POJ1016
- POJ1016
- poj1016
- poj1016
- poj1016
- poj1016
- poj1016
- poj1016
- poj1016
- poj1016
- poj1016
- poj1016 模拟
- 北大ACM poj1016
- poj1016:Numbers That Count
- POJ1016 Numbers That Count
- poj1016--字符串处理
- poj1016 Numbers That Count
- poj1016-Numbers That Count
- 两种方法上传本地文件到github
- android SQLite使用SQLiteOpenHelper类对数据库进行操作
- 【bzoj4195】[Noi2015]程序自动分析
- 谷歌浏览器的快捷键
- 经典算法,yuv与rgb互转,查表法,让你的软件飞起来
- poj1016
- 你不知道的console
- Struts2——1.创建Struts项目
- keepalived+nginx实现双机热备(防止单点故障)
- [系分] Function Model
- windows下安装gcc
- google框架的安装方法
- APK SDK 脱壳技术 反编译
- LinearLayout代码中addView默认LayoutParams