Numbers That Count
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 20396   Accepted: 6817

Description

"Kronecker's Knumbers" is a little company that manufactures plastic digits for use in signs (theater marquees, gas station price displays, and so on). The owner and sole employee, Klyde Kronecker, keeps track of how many digits of each type he has used by maintaining an inventory book. For instance, if he has just made a sign containing the telephone number "5553141", he'll write down the number "5553141" in one column of his book, and in the next column he'll list how many of each digit he used: two 1s, one 3, one 4, and three 5s. (Digits that don't get used don't appear in the inventory.) He writes the inventory in condensed form, like this: "21131435".

The other day, Klyde filled an order for the number 31123314 and was
amazed to discover that the inventory of this number is the same as the
number---it has three 1s, one 2, three 3s, and one 4! He calls this an
example of a "self-inventorying number", and now he wants to find out
which numbers are self-inventorying, or lead to a self-inventorying
number through iterated application of the inventorying operation
described below. You have been hired to help him in his investigations.

Given any non-negative integer n, its inventory is another integer
consisting of a concatenation of integers c1 d1 c2 d2 ... ck dk , where
each ci and di is an unsigned integer, every ci is positive, the di
satisfy 0<=d1<d2<...<dk<=9, and, for each digit d that
appears anywhere in n, d equals di for some i and d occurs exactly ci
times in the decimal representation of n. For instance, to compute the
inventory of 5553141 we set c1 = 2, d1 = 1, c2 = 1, d2 = 3, etc., giving
21131435. The number 1000000000000 has inventory 12011 ("twelve 0s, one
1").

An integer n is called self-inventorying if n equals its inventory.
It is called self-inventorying after j steps (j>=1) if j is the
smallest number such that the value of the j-th iterative application of
the inventory function is self-inventorying. For instance, 21221314 is
self-inventorying after 2 steps, since the inventory of 21221314 is
31321314, the inventory of 31321314 is 31123314, and 31123314 is
self-inventorying.

Finally, n enters an inventory loop of length k (k>=2) if k is
the smallest number such that for some integer j (j>=0), the value of
the j-th iterative application of the inventory function is the same as
the value of the (j + k)-th iterative application. For instance,
314213241519 enters an inventory loop of length 2, since the inventory
of 314213241519 is 412223241519 and the inventory of 412223241519 is
314213241519, the original number (we have j = 0 in this case).

Write a program that will read a sequence of non-negative integers
and, for each input value, state whether it is self-inventorying,
self-inventorying after j steps, enters an inventory loop of length k,
or has none of these properties after 15 iterative applications of the
inventory function.

Input

A
sequence of non-negative integers, each having at most 80 digits,
followed by the terminating value -1. There are no extra leading zeros.

Output

For
each non-negative input value n, output the appropriate choice from
among the following messages (where n is the input value, j is a
positive integer, and k is a positive integer greater than 1):

n is self-inventorying

n is self-inventorying after j steps

n enters an inventory loop of length k

n can not be classified after 15 iterations

Sample Input

22
31123314
314213241519
21221314
111222234459
-1

Sample Output

22 is self-inventorying
31123314 is self-inventorying
314213241519 enters an inventory loop of length 2
21221314 is self-inventorying after 2 steps
111222234459 enters an inventory loop of length 2

Source

题意:
水题题意太繁就不写了吧。
代码:
 /*
坑爹的题,简单的模拟只是字符串处理不好弄,刚开始想用itoa函数直接把数字加到字符串后面,但在POJ上ce了应该是不支持这个函数
后来发现一个数字竟然可以赋值给一个字符变量,这样就可以把数字一个一个的加到字符数组里(最后要把\0加到字符数组里),C学的不好。
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
char ch[][];
int a[];
int main()
{
while(scanf("%s",&ch[])!=EOF)
{
if(!strcmp(ch[],"-1")) break;
bool flag=;
for(int k=;k<=;k++){
memset(a,,sizeof(a));
int lne=strlen(ch[k-]);
for(int i=;i<lne;i++)
a[ch[k-][i]-'']++;
char s[];
int t=;
for(int i=;i<;i++)
{
if(a[i]==)
continue;
if(a[i]>=)
{
s[t++]=a[i]/+'';
s[t++]=a[i]%+'';
}
else s[t++]=a[i]+'';
s[t++]=i+'';
}
s[t]='\0';
if(!strcmp(s,ch[k-]))
{
if(k==)
printf("%s is self-inventorying\n",ch[]);
else
printf("%s is self-inventorying after %d steps\n",ch[],k-);
flag=;
}
else
{
for(int i=k-;i>=;i--)
if(!strcmp(s,ch[i]))
{
printf("%s enters an inventory loop of length %d\n",ch[],k-i);
flag=;
break;
}
}
if(flag) break;
strcpy(ch[k],s);
}
if(!flag)
printf("%s can not be classified after 15 iterations\n",ch[]);
}
return ;
}

POJ 1016 模拟字符串的更多相关文章

  1. POJ 1016

    http://poj.org/problem?id=1016 一道字符串处理的题目,理解题意后注意细节就好. 题意:每一串数字 都可以写成 a1 b1 a2 b2 ....ai bi 其中ai是指bi ...

  2. 二叉搜索树的结构(30 分) PTA 模拟+字符串处理 二叉搜索树的节点插入和非递归遍历

    二叉搜索树的结构(30 分) PTA 模拟+字符串处理 二叉搜索树的节点插入和非递归遍历   二叉搜索树的结构(30 分) 二叉搜索树或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则 ...

  3. 模拟/字符串处理 UVALive 6833 Miscalculatio

    题目传送门 /* 模拟/字符串处理:主要是对*的处理,先把乘的预处理后再用加法,比如说是:1+2*3+4 = 1+..6+4 = 11 */ #include <cstdio> #incl ...

  4. POJ 1159 Palindrome(字符串变回文:LCS)

    POJ 1159 Palindrome(字符串变回文:LCS) id=1159">http://poj.org/problem? id=1159 题意: 给你一个字符串, 问你做少须要 ...

  5. poj 1016 Numbers That Count

    点击打开链接 Numbers That Count Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17922   Accep ...

  6. java基础知识回顾之---java String final类普通方法的应用之“模拟字符串Trim方法”

    /* * 4,模拟一个trim功能一致的方法.去除字符串两端的空白  * 思路: * 1,定义两个变量. * 一个变量作为从头开始判断字符串空格的角标.不断++. * 一个变量作为从尾开始判断字符串空 ...

  7. POJ 3865 - Database 字符串hash

    [题意] 给一个字符串组成的矩阵,规模为n*m(n<=10000,m<=10),如果某两列中存在两行完全相同,则输出NO和两行行号和两列列号,否则输出YES [题解] 因为m很小,所以对每 ...

  8. POJ 3974 - Palindrome - [字符串hash+二分]

    题目链接:http://poj.org/problem?id=3974 Time Limit: 15000MS Memory Limit: 65536K Description Andy the sm ...

  9. TZOJ 4865 统计单词数(模拟字符串)

    描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次数. 现在,请你编程实现这一功能,具体要求是:给定一个单词,请你输出它在给定的 ...

随机推荐

  1. input实时监控和获取焦点的问题,oninput,ononfocus

    1.input监控实时输入问题,google浏览器使用oninput,其他浏览器(IE6/7/8)使用onpropertychange var ie = !!window.ActiveXObject; ...

  2. Arduino101学习笔记(四)—— 数字IO

    1.设置管脚模式 //***************************************************************************************** ...

  3. spring实例教程

    1.配置好spring mvc发现访问无法匹配,很可能是文件放的位置或者相对目录不对. 2.实例大全:http://www.yiibai.com/spring/spring-collections-l ...

  4. 定时备份mysql

    @echo offset filename=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%mysqldump -- ...

  5. 深入理解KMP算法

    前言:本人最近在看<大话数据结构>字符串模式匹配算法的内容,但是看得很迷糊,这本书中这块的内容感觉基本是严蔚敏<数据结构>的一个翻版,此书中给出的代码实现确实非常精炼,但是个人 ...

  6. Liferay 6.2 改造系列之二十二:如何发布WAR包

    1.修改web资源并发布 如果修改了默认主题信息,需执行portal-web中的build-themes任务: 执行portal-web中的deploy任务: 2.修改portal-impl中的jav ...

  7. windows修改虚拟内存

    右键电脑属性: 高级系统设置: 性能设置: 虚拟内存更改:

  8. JavaScript笔试必备语句

    1. document.write( " "); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document- >html- >(head,bod ...

  9. item上下自动循环滚动显示

    //li 上下滚动 (function($){ $.fn.extend({ Scroll:function(opt,callback){ //参数初始化 if(!opt) var opt={}; va ...

  10. linux tomcat配置https

    自己生成一个ssl证书,因为是自己生成的所以该证书,不被浏览器信任(具体表现https前面有个X) [root@centos apache-tomcat-]# keytool -genkey -ali ...