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

这个题要被自己蠢哭了,写了好久,一直结果错误,然而并没有发现结果错误在哪!!!

之后发现是忽略了  0

仍然结果错误!!!!!!!

原因  memset函数 忘了写头文件   <string.h>   !!!!!

#include <iostream>
#include <string>
#include <string.h>
using namespace std;
string g(string str)
{
int x[],i,j=,n=str.length();
char s[];
memset(x,,sizeof(x));
for(i=;i<n;i++)x[str[i]-]++;
for(i=;i<;i++){
if(x[i]){
if(x[i]<){
s[j++]=x[i]+;
}
else{
s[j++]=x[i]/+;
s[j++]=x[i]%+;
}
s[j++]=i+;
}
}
s[j]='\0';
return s;
}
void f(string str)
{
int i,p=,x=str.length();
string s=str;
string str1[];
bool flag;
for(i=;i<;i++){
s=g(s);
flag=false;
for(p=;p<i;p++)
if(s==str1[p]){
flag=true;
break;
}
if(flag){
break;
}
str1[i]=s;
}
cout<<str;
if(flag){
if(i==&&!p)cout<<" is self-inventorying "<<endl;
else if(i-==p)cout<<" is self-inventorying after "<<i<<" steps "<<endl;
else cout<<" enters an inventory loop of length "<<i-p<<" "<<endl;
}
else cout<<" can not be classified after 15 iterations "<<endl;
}
int main(void)
{
string str;
while(cin>>str){
if(str=="-1")break;
f(str);
}
return ;
}

注意 各函数之间对字符串string的调用,转换!

B - Numbers That Count的更多相关文章

  1. poj 1016 Numbers That Count

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

  2. POJ1016 Numbers That Count

    题目来源:http://poj.org/problem?id=1016 题目大意: 对一个非负整数定义一种运算(inventory):数这个数中各个数字出现的次数,然后按顺序记录下来.比如“55531 ...

  3. Numbers That Count POJ - 1016

    "Kronecker's Knumbers" is a little company that manufactures plastic digits for use in sig ...

  4. POJ 1016 Numbers That Count 不难,但要注意细节

    题意是将一串数字转换成另一种形式.比如5553141转换成2个1,1个3,1个4,3个5,即21131435.1000000000000转换成12011.数字的个数是可能超过9个的.n个m,m是从小到 ...

  5. Random Numbers Gym - 101466K dfs序+线段树

    Tamref love random numbers, but he hates recurrent relations, Tamref thinks that mainstream random g ...

  6. 2017 ACM-ICPC, Universidad Nacional de Colombia Programming Contest K - Random Numbers (dfs序 线段树+数论)

    Tamref love random numbers, but he hates recurrent relations, Tamref thinks that mainstream random g ...

  7. Java中有关Null的9件事

    对于Java程序员来说,null是令人头痛的东西.时常会受到空指针异常 (NPE)的骚扰.连Java的发明者都承认这是他的一项巨大失误.Java为什么要保留null呢?null出现有一段时间了,并且我 ...

  8. POJ题目排序的Java程序

    POJ 排序的思想就是根据选取范围的题目的totalSubmittedNumber和totalAcceptedNumber计算一个avgAcceptRate. 每一道题都有一个value,value ...

  9. LeetCode "477. Total Hamming Distance"

    Fun one.. the punch line of this problem is quite common in Bit related problems on HackerRank - vis ...

随机推荐

  1. SQL重复记录查询的几种方法(转)

    1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 代码如下: select * from people ) 2.删除表中多余的重复记录,重复记录是根据单个字段(people ...

  2. 初识Treap

    Treap,简单的来说就是Tree+Heap,是一颗平衡树,每个节点有两个信息:1.key:当前节点的关键字 :2.fix:当前节点优先级.key满足二叉排序数的性质,即左儿子都比当前节点小,右儿子都 ...

  3. CDZSC_2015寒假新人(2)——数学 B

    B - B Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  4. 【Python网络编程】多线程聊天软件程序

    课程设计的时候制作的多线程聊天软件程序 基于python3.4.3 import socket import pickle import threading import tkinter import ...

  5. 身份证校验程序(上)- 零基础入门学习Delphi48

    身份证校验程序 让编程改变世界 Change the world by program [caption id="attachment_2699" align="alig ...

  6. HTML条件注释用法诠释

    HTML条件注释用法诠释 注释内容以样式为例,如下: 1.支持所有IE浏览器 <!--[if IE]> <link rel="stylesheet" href=& ...

  7. Extjs Tooltip属性的使用

    要想让 tooltip生效必须:Ext.QuickTips.init();

  8. 老了,问题定位难了,xml编码解析

    同样一个程序,在A机器好用,在B机器不好用,怀疑过jdk版本位数问题,怀疑过其他. 最后,突然发现出错的全是xml中文,想到是不是编码问题,一看环境变量果真一个gbk,一个utf-8,再一看 程序,没 ...

  9. BZOJ 1084 最大子矩阵

    http://www.lydsy.com/JudgeOnline/problem.php?id=1084 思路:分m=1和m=2操作 #include<algorithm> #includ ...

  10. WPF笔记(1.10 绘图)——Hello,WPF!

    原文:WPF笔记(1.10 绘图)--Hello,WPF! 书中的代码语法过时了,改写为以下(测试通过):         <Button>            <Button.L ...