Numbers That Count POJ - 1016
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
Output
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
这是一道模拟题,题目根据你的字符串有三种求法.重点是理解第三种,即在几步之后与原来的字符串相等(只要与前面出现过的字符串相等即可!!!)
#include <iostream>
#include <cstdio>
#include <cstring>
#define maxn 85
using namespace std; char s[maxn];
int a[]; int main()
{
while()
{
char str[][maxn]= {}; //先全部变换,将原始数字和变换后的都保存下来
memset(s,,sizeof(s)); //初始化
scanf("%s",s);
if(s[]=='-')
break;
strcpy(str[],s);
for(int i=; i<; i++) //15次变换
{
memset(a,,sizeof(a)); //初始化
for(int j=; j<; j++) //查找0~9每个数字,并保存至数字a[j]
for(int k=; k<strlen(str[i]); k++)
{
if(str[i][k]==j+'')
a[j]++;
}
for(int j=,k=; j<; j++)
if(a[j]>=) //这里的细节需要注意一下,个数大于或等于10,需要保存三位数
{
str[i+][k]=a[j]/+'';
str[i+][k+]=a[j]%+'';
str[i+][k+]=j+'';
k+=;
}
else if(a[j]> && a[j]<)
{
str[i+][k]=a[j]+'';
str[i+][k+]=j+'';
k+=;
}
}
bool flag=true;
if(strcmp(str[],str[])==)
{
printf("%s is self-inventorying\n",str[]);
flag=false;
}
if(flag)
for(int i=; i<=; i++)
if(strcmp(str[i],str[i+])==)
{
printf("%s is self-inventorying after %d steps\n",str[],i);
flag=false;
break;
}
if(flag)
for(int i=; i>=; i--)
if(strcmp(str[],str[i])==)
{
printf("%s enters an inventory loop of length %d\n",str[],-i);
flag=false;
break;
}
if(flag)
printf("%s can not be classified after 15 iterations\n",str[]);
}
return ;
}
Numbers That Count POJ - 1016的更多相关文章
- poj 1016 Numbers That Count
点击打开链接 Numbers That Count Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17922 Accep ...
- POJ1016 Numbers That Count
题目来源:http://poj.org/problem?id=1016 题目大意: 对一个非负整数定义一种运算(inventory):数这个数中各个数字出现的次数,然后按顺序记录下来.比如“55531 ...
- POJ 1016 模拟字符串
Numbers That Count Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20396 Accepted: 68 ...
- POJ 1016 Numbers That Count 不难,但要注意细节
题意是将一串数字转换成另一种形式.比如5553141转换成2个1,1个3,1个4,3个5,即21131435.1000000000000转换成12011.数字的个数是可能超过9个的.n个m,m是从小到 ...
- POJ 1016
http://poj.org/problem?id=1016 一道字符串处理的题目,理解题意后注意细节就好. 题意:每一串数字 都可以写成 a1 b1 a2 b2 ....ai bi 其中ai是指bi ...
- Self Numbers 分类: POJ 2015-06-12 20:07 14人阅读 评论(0) 收藏
Self Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22101 Accepted: 12429 De ...
- B - Numbers That Count
Description "Kronecker's Knumbers" is a little company that manufactures plastic di ...
- POJ 2739 Sum of Consecutive Prime Numbers(素数)
POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...
- POJ题目排序的Java程序
POJ 排序的思想就是根据选取范围的题目的totalSubmittedNumber和totalAcceptedNumber计算一个avgAcceptRate. 每一道题都有一个value,value ...
随机推荐
- 基于TP5.1实用案例及教程
推荐<基于TP5.1实用案例及教程>书 目录: 通用封装 Export通用封装Import通用封装配合Import通用封装的ImportBaseVerify类Files通用封装Direct ...
- Maven从入门到放弃
1.maven是什么? maven是Apache下的一个纯java开发的一个开源项目,它是一款能够抽象构建过程,并且提供依赖管理,中央仓库,自动下载构建等功能的项目构建工具. 2.为什么要使用mave ...
- 搭建Springboot网站有感
最近心血来潮,搭建了个人网站,一方面想学习下新的知识,另一方面也想有个作品,在这分享下自己的体会,先不说知识点. 建站容易吗,因人而异,而我在完成这个最最简单的工作时起码经历了3个阶段不同的心理变化, ...
- 电脑查询pico的mac
配置好adb或者sdk后, adb shell cat /sys/class/net/wlan0/address
- Gin + Vue全栈开发实战(一)
Gin入门 本章概要 Gin简介 开发第一个Gin程序 1.1 Gin简介 Gin是用Go语言编写的一个轻量级Web应用框架,现在在各个公司包括字节跳动.bilibili等大互联网公司都得到了广泛的应 ...
- alpine 镜像 java 日志中文问号乱码
0x00 前言 吾使用 alpine 作为基础镜像构建了 jdk8 镜像,为线上业务的 java 微服务架构提供支持,但是有容器运行的 java 服务中打印的日志中一旦出现中文,就会出现诸如以下的 ? ...
- 100天搞定机器学习|Day35 深度学习之神经网络的结构
100天搞定机器学习|Day1数据预处理 100天搞定机器学习|Day2简单线性回归分析 100天搞定机器学习|Day3多元线性回归 100天搞定机器学习|Day4-6 逻辑回归 100天搞定机器学习 ...
- maven阿里云镜像setting
<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://mav ...
- 自然语言处理(NLP)的一般处理流程!
1. 什么是NLP 自然语言处理 (Natural Language Processing) 是人工智能(AI)的一个子领域.自然语言处理是研究在人与人交互中以及在人与计算机交互中的语言问题的一门学科 ...
- Linux下Kafka下载与安装教程
原文链接:http://www.studyshare.cn/software/details/1176/0 一.预备环境 Kafka是java生态圈中的一员,运行在java虚拟机上,按Kafka官方说 ...