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. pca图像识别

    代码下载:基于PCA(主成分分析)的人脸识别 人脸识别是一个有监督学习过程,首先利用训练集构造一个人脸模型,然后将测试集与训练集进行匹配,找到与之对应的训练集头像.最容易的方式是直接利用欧式距离计算测 ...

  2. 01 日志组件XLog

    本文地址为:http://www.cnblogs.com/ADTL/p/5357259.html XLog为XCode的日志组件,为系统基本功能. 使用示例: 1.新建WinForm程序 2.引用Ne ...

  3. (转) 制作 Clonezilla live 启动盘

    GNU/Linux Method A: Tuxboot 下載 GNU/Linux 版本使用的 Tuxboot 在您的環境 在 GNU/Linux 下, 請依 指示 來執行 Tuxboot 並安裝再生龍 ...

  4. (转) 谈C/C++指针精髓

    原文:http://www.cnblogs.com/madengwei/archive/2008/02/18/1072410.html   [摘要]    指针是C和C++语言编程中最重要的概念之一, ...

  5. 简易的WPF MVVM模式开发

    Model层 public class Song { private string _artistName; private string _songTitle; public string Song ...

  6. dojo Tree 添加、删除节点

    var tree=this.tree; var store=tree.model.store; if(this.node){ console.log(this.node) var children=t ...

  7. CodeForces 25E Test KMP

    Description Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tes ...

  8. javascript之Arguments

    一.Arguments.callee //获取当前正在执行的函数,也就是这个函数自身,常用于获取匿名函数自身 语法:arguments.callee var factorial = function ...

  9. 【转】android是32-bit系统还是64-bit系统

    原文网址:http://www.cnblogs.com/pengwang/archive/2013/03/11/2954496.html 电脑CPU分32位和64位,这个我们都知道.用了这么长时间的a ...

  10. MFC DestroyWindow窗口对象和窗口句柄的销毁

    考虑单窗口情况: 假设自己通过new创建了一个窗口对象pWnd,然后pWnd->Create.则销毁窗口的调用次序: 1. 手工调用pWnd->DestroyWindow(): 2. De ...