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. PHP学习笔记三十【final】

    <?php //final不能去修饰属性(变量) //如果希望类不希望被继承就可以使用final关键字 final class Person() { public function sayHi( ...

  2. java开发webservice

    第一部分:相关下载配置 1.开发环境   eclipse-jee-mars-2-win32-x86_64.zip  http://www.eclipse.org/downloads/index-pac ...

  3. [Head First Python]3. 文件与异常:处理错误

    datafile.txt Man: Is this the right room for an argument? Other Man: I've told you once. Man: No you ...

  4. wdcp/wdlinux 在 UBUNTU/linux 中安装失败原因之创建用户

    根本原因在于安装时创建的用户www 使用了和ubuntu已创建的用户,冲突了自然创建不了用户. 你可以修改lanmp.sh脚本中创建www用户时的代码,将1000改为其他数字. 也可以修改当前用户的U ...

  5. 安装好ubuntu之后要干的几件事

    安装完ubuntu之后啊,系统除了自带了firefox,libre office等能用,要应付日常需求还差了些.然后我根据最近我的需求写了个清单.完成这个清单就让ubuntu成了一个得心应手的好工具了 ...

  6. wget 测试cdn

    可以通过wget 或curl 指定代理ip来访问同一个链接的不同cdn响应页面.来测试不同cdn间的数据同步问题.

  7. poj 1699 Best Sequence

    http://poj.org/problem?id=1699 题意:给你n个长度为L的序列,求包含这几个序列的最短长度. 先预处理每两个序列之间的关系,然后dfs枚举就行. #include < ...

  8. Delphi之通过代码示例学习XML解析、StringReplace的用法(异常控制 good)

    *Delphi之通过代码示例学习XML解析.StringReplace的用法 这个程序可以用于解析任何合法的XML字符串. 首先是看一下程序的运行效果: 以解析这样一个XML的字符串为例: <? ...

  9. 线程初步了解 - <第一篇>

    操作系统通过线程对程序的执行进行管理,当操作系统运行一个程序的时候,首先,操作系统将为这个准备运行的程序分配一个进程,以管理这个程序所需要的各种资源.在这些资源之中,会包含一个称为主线程的线程数据结构 ...

  10. git与svn的使用比较

    先说下基础知识: git是本地会(维护)有个版本仓库. svn本地也会维护一个自己的信息(一般是目录结构和文件状态的信息),这里的文件状态一般是指:文件是已删除,还是已添加,还是被修改等等.一般是会有 ...