poj 1016 Numbers That Count

POJ1016-Numbers That Count【字符串处理】 北大POJ1016-Numbers That Count【字符串处理】 解题报告+AC代码 立即下载

Numbers That Count
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 19905 Accepted: 6671

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


判断字符串问题


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int cmp(const void *p1,const void *p2) {
	return *(char *)p1-*(char *)p2;
}
int v[85];
char a[85],c[16][85];
char p[4];
int main() {
	int k,i,j,cnt;
	while(scanf("%s",a)) {
		if(strcmp("-1",a)==0) break;
		memset(c,0,sizeof(c));		
		strcpy(c[0],a);
		for(k=0;k<=14;k++) { //循环15次 
			memset(v,0,sizeof(v));
			qsort(c[k],strlen(c[k]),sizeof(c[k][0]),cmp);
			// 判断有几位相同的数 
			for(i=0;i<strlen(c[k]);i++) {
				if(v[i]) continue;  //遍历过的就不再遍历 
				cnt=0;
				for(j=i;j<strlen(c[k]);j++) {
					if(v[j]) continue;
					if(c[k][i]==c[k][j])
						cnt++,v[j]=1;
				}
				//  数字转换成字符串 ,最后一位是 '\0'
				if(cnt<=9) p[0]=cnt+'0',p[1]=c[k][i],p[2]='\0';
				else {
					p[0]=cnt/10+'0';
					p[1]=cnt%10+'0';
					p[2]=c[k][i];
					p[3]='\0';
				}								
			//	itoa(cnt*10+(c[k][i]-'0'),p,10);
				strcat(c[k+1],p);				
			}
		}	
		if(strcmp(c[0],c[1])==0) {  //本身就可以 
			printf("%s is self-inventorying\n",a);
			continue;
		}	
		bool f1=true,f2=true;
		for( i=1;i<=15;i++) {						
			if(strcmp(c[i],c[i+1])==0) {  //判断多少步之后成self-inventorying
				printf("%s is self-inventorying after %d steps\n",a,i+1);
				f1=false;break;
			}
			for(j=0;j<i;j++){   //判断是否成 inventory
				if(strcmp(c[i],c[j])==0) {
					printf("%s enters an inventory loop of length %d\n",a,i-j);
					f2=false;break;
				}
			} 
			if(!f2) break; // inventory已成立 ,结束本次循环 
		}    //都不成立,输出 
		if(f1&&f2)printf("%s can not be classified after 15 iterations\n",a);	
		memset(a,0,sizeof(a));		
	}
	return 0;
} 



【零基础入门哈希签名架构,从Lamport到SPHINCS+】第二集 哈希签名树 Merkle Tree Authentication 在第一集中,我们一直忽略了一个问题。设想一下,假如有一个Hacker(黑客),在截获到Sender发送给Receiver的公钥之后,把这个公钥改成Hacker自己的公钥,然后再发给Receiver,那么Receiver就会误认为这是Sender的公钥。所以我们之前所说放方案,其安全性都需要建立在一个前提下:Receiver需要确认公钥确实是Sender发出的。 阅读详情

相关推荐

Android Camera性能优化概述

做camera性能优化方面的工作有几年了,想写一篇文章简单介绍一下其中涉及到的具体技术,这篇文章会大概介绍一下涉及到的技术。

weixin_42136255的博客 4025

POJ 1016 Numbers That Count

题目链接:http://poj.org/problem?id=1016

Saber 572

从论文到生产:iSLIP优先级匹配算法在SDN交换机中的20年演进史

本文回顾了iSLIP优先级匹配算法在SDN交换机中的20年演进历程,从斯坦福大学的原始论文到现代芯片实现。通过独特的指针滑动和迭代循环机制,iSLIP算法显著提升了交换机的吞吐量和公平性,解决了传统FIFO调度的队头阻塞问题。文章详细探讨了算法在硬件实现中的工程挑战、开源实践及未来AI时代的智能调度方向。

weixin_29230649的博客 331

poj1016

Problem : Numbers That Count

DreamtaleL 485

睿尔曼超轻量仿人机械臂--医疗工作站运行Demo(Python)

开发环境系统:win10Python版本:python 3.11.2由于机械臂相关软件版本不定期更新,如果你使用的软件接口或协议与本文有出入,请联系官方技术人员及时更新。

realman_Rop的博客 1094

华为昇腾服务器npu中安装paddle,pytorch等环境,训练代码迁移适配等问题记录

参考文档:https://github.com/PaddlePaddle/PaddleCustomDevice/blob/develop/backends/npu/README_cn.md

qq_29220369的博客 4112

WELCOME THE NEW GAY

TECHNOLOGY: HTML,ASP with vbscript,ASPX with c#,javascript,XML bata software using,new software finding studing software designing basic computer technology

RbmxXx's Blog 5391

vue高德地图POI关键字搜索定位

最近在项目中遇到了关于地图的问题,首先为了满足需求从而使用的是JSAPI为2.0版本的。需求是根据关键字搜索定位到该位置。值得注意的是在使用 AMap.Event.addListener时 Event一定要大写的E,不然页面会报错。在地图上定义一个输入框,根据输入的位置进行提示,然后点击后跳转到对应的位置并打点标记。JSAPI主要使用这两个。

YL 2136

POJ1016 Numbers That Count

Numbers That Count Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16942   Accepted: 5555 Description "Kronecker's Knumbers" is a little company that man

天堂人间 1320

【小白深度教程 1.32】手把手教你从多视角图像进行 3D 重建(SfM 算法)

重建的目标是从一组照片中推导场景的几何结构,假设摄像机位置和内部参数是已知的或可以从图像集中猜测。 这是通过使用多个照片,在其中应用运动结构法(Structure from Motion,SfM)来解决像素级对应问题,部分地恢复3D信息来实现的。

2401_87064292的博客 2160

扣子Coze智能体万字教程:从入门到精通,一文掌握AI工作流搭建

智能体 = 角色设定 + 提示词 + 变量输入一个好提示词的核心是结构、风格和复用性创建后可以一键发布成网页应用、对话助手整个过程0代码,只靠配置,人人可学,人人可用四、进阶一:理解「工作流」的威力如果你已经用扣子创建了几个简单的智能体,比如写个爆款小红书文案、生成一段短视频脚本,那恭喜你已经入门。但如果你还停留在“一个智能体 = 一段提示词”的层级,你离真正的智能体生产力革命,还差一步:学会搭建“工作流”——让多个大模型自动协同完成任务。

互联网架构师笔记 3508

[POJ][1016]Numbers That Count

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, Klyd

软件工程学森 1799

手把手教你学GPU的KMD专栏--3.1 设备初始化流程深度解析

本文深入解析了KMD(内核模式驱动)设备初始化流程,这是GPU驱动开发最基础且关键的环节。初始化流程包括6个核心阶段:KMD模块加载、PCIe设备探测匹配、GPU硬件初始化、显存分配映射、中断系统配置和设备注册。每个阶段都有详细步骤解析,涉及关键数据结构和错误处理机制。文章还分析了常见问题(驱动加载失败、显存分配失败、中断配置失败)的解决方案,并指出未来趋势将向动态初始化、安全增强和AI优化方向发展。正确高效的初始化流程是确保GPU被操作系统安全使用的前提,也是后续内存管理、任务调度等功能的基础。

MHD0815的博客 262

POJ-1016 Numbers That Count

题目大意:对于一个由数字组成的串,可以变换为c1 d1 c2 d2 ... ck dk形式的串,表示原串中数字di出现了ci次。若变换前后的串相等,则称该串具有self-inventorying属性。比如31123314。 对某一串n,连续进行若干次该变换可能出现以下某一种情况: 1.立即出现self-inventorying属性 2.变换i次后出现self-inventorying属性

u011468264的专栏 447

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

poj1016-Numbers That Count

模拟题poj1016-Numbers That Count Description "Kronecker's Knumbers" is a little company that manufactures plastic digits for use in signs (theater marquees, gas station price displays,

Just do IT! 901

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

POJ1016 Numbers That Count ,<vector>

题目: Numbers That Count Time Limit:1000MS Memory Limit:10000K Total Submissions:21991 Accepted:7410 Description "Kronecker's Knumbers" is a little company that manufactures p...

s0il的博客 383

POJ 一 1016 Numbers That Count

Numbers That Count Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17897   Accepted: 5932 Description "Kronecker's Knumbers" is a little company that manufac

小华在努力~ 660

POJ1016-Numbers That Count

全解题报告索引目录 -> 【北大ACM – POJ试题分类】 转载请注明出处:http://exp-blog.com ------------------------------------------------------------------------- 大致题意: 题意不难懂,对于任意的数字串n,都可以压缩存储为 c1 d1 c2 d2 .... ck d...

ζёСяêτ - 小優YoU 7021

poj1016 Numbers That Count

B - Numbers That Count Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1016 Appoint description:  System Crawler  (2016-05-10)

苏苏爱自由 1969

POJ 1016 Numbers That Count

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, K...

ZRP442235的博客 188

POJ-1016-Numbers That Count

POJ-1016-Numbers That Count

kaven 9053

北大ACM(POJ1016-Numbers That Count)

Question:http://poj.org/problem?id=1016 问题点:水题。 1 Memory: 232K Time: 125MS 2 Language: C++ Result: Accepted 3 4 #include <iostream> 5 #include <string> 6...

aenv6574的博客 201
上一篇: poj 1088 滑雪
下一篇: hdu 1203 I NEED A OFFER!
数星星的夜晚
博客等级 码龄11年 8粉丝 104原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值