1140 Look-and-say Sequence (20 point(s))

D触发器(D Flip-Flop)与D锁存器(D Latch) 在解释这个练习题之前,我们先来简单回顾一下D触发器(D flip-flop)和D锁存器(D latch)的概念,以及它们在数字电路中的作用。这将帮助我们理解所提到的练习。 阅读详情

1140 Look-and-say Sequence (20 point(s))

Look-and-say sequence is a sequence of integers as the following:

D, D1, D111, D113, D11231, D112213111, ...

where D is in [0, 9] except 1. The (n+1)st number is a kind of description of the nth number. For example, the 2nd number means that there is one D in the 1st number, and hence it is D1; the 2nd number consists of one D(corresponding to D1) and one 1 (corresponding to 11), therefore the 3rd number is D111; or since the 4th number is D113, it consists of one D, two 1's, and one 3, so the next number must be D11231. This definition works for D = 1 as well. Now you are supposed to calculate the Nth number in a look-and-say sequence of a given digit D.

Input Specification:

Each input file contains one test case, which gives D (in [0, 9]) and a positive integer N (≤ 40), separated by a space.

Output Specification:

Print in a line the Nth number in a look-and-say sequence of D.

Sample Input:

1 8

Sample Output:

1123123111

模拟题。思路比较简单。

注意点:

1. int2string()的实现;

2. 在nextString()遍历完成后,还需要针对字符串末尾的结果处理。

#include<iostream>
#include<cstring>
using namespace std;
string int2string(int n){
	string ans ="";
	do{
		ans = char(n%10+'0')+ans;
		n/=10;
	}while(n);
	return ans;
}
string nextString(string s){
	int cnt=0;string ans = "";
	for(int i=0;i<s.length();i++){
		if(i==0) cnt=1;
		else{
			if(s[i]==s[i-1]){
				cnt++;
			} 
			else{
				ans += s[i-1];
				ans += int2string(cnt);
				cnt=1;
			}
		}
	}
	ans+= s[s.length()-1];
	ans+= int2string(cnt);
	return ans;
}
int main(void){
	string s;int N;cin>>s>>N;
	if(N>=2){
		for(int i=0;i<N-1;i++){
			s = nextString(s);
		}
	} 
	cout<<s<<endl;
	return 0;
}

 

Qt Location实战:5分钟搞定地图插件切换与卫星图源加载(附完整代码) 本文是Qt Location开发系列教程的实战指南,详细讲解如何在Qt应用中快速实现地图插件(如Esri、OSM、MapboxGL)的动态切换与卫星图源的加载。通过清晰的代码示例,帮助开发者理解插件机制,解决常见配置问题,并在5分钟内构建出具备交互式地图切换功能的应用程序。 阅读详情

相关推荐

计算机模拟爆破过程,基于LSDYNA岩石爆破模拟建模分析

原标题:基于LSDYNA岩石爆破模拟建模分析 Ls Dyna岩石爆破模拟仿真作者:dyna_focus擅长领域:dyna/abaqus/hypermesh一、 数值模型的建立1.1 单元及算法的选择岩石,炸药,空气都采用solid164实体单元。岩石采用常应力实体单元,该种单元属于纯粹的lagrange算法,该种算法单元网格附着在材料上,随着材料的流动而产生单元网格的变形,但是在结构变形巨大时,有...

weixin_29494379的博客 7317

PAT 1140 Look-and-say Sequence python解法

1140 Look-and-say Sequence (20 分) Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D112213111, … where D is in [0, 9] except 1. The (n+1)st number is a kind...

qq_36936510的博客 378

【事件相机实战】噪声识别与智能滤波技术解析

本文深入解析了事件相机应用中关键的噪声识别与智能滤波技术。针对背景活动噪声、阈值波动噪声、热点噪声及运动边缘尾迹等核心噪声类型,文章剖析了其成因与特征,并详细介绍了从经典的时空相关性滤波、热点像素滤除到前沿的深度学习(如EDnCNN)等实战滤波方法,旨在帮助开发者在保证低延迟的前提下,有效提升事件流数据质量。

weixin_29169899的博客 439

1140 Look-and-say Sequence(22行代码+详细注释)

分数 20全屏浏览题目切换布局作者 CHEN, Yue单位 浙江大学whereDDD1;DD1D111;

m0_66329385的博客 412

ROS——无人机ROS仿真包 rotors_simulator 编译教程

文章目录 安装wstool sudo apt install python3-wstool 创建ROS工程 $ mkdir -p ~/UAV/src $ cd ~/UAV/src $ catkin_init_workspace # initialize your catkin workspace $ wstool init 下载源码 git clone git@github.com:ethz-asl/rotors_simulator.git 源码链接: https://github.com/eth

漫长IT路 5864

ESP32-CAM与TFT屏幕实时图像传输:Arduino环境下的OV2640驱动实践

本文详细介绍了在Arduino环境下实现ESP32-CAM与TFT屏幕实时图像传输的完整实践方案。重点解析了OV2640摄像头的驱动配置、硬件引脚连接、TFT屏幕初始化及图像显示优化技巧,帮助开发者快速构建稳定的实时图像显示系统,适用于物联网监控、门禁系统等场景。

cuda7parallel的博客 115

PAT-python-1140 Look-and-say Sequence

Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D112213111, … where D is in [0, 9] except 1. The (n+1)st number is a kind of description of the nth number. For example, the 2nd number means that there is one D i

陆沙的博客 887

uniapp开发小程序保存图片权限获取失败一直走fail?本地能保存,线上版就不行! 原来是这个问题!

通过这次经历,我发现线上版小程序和开发版、体验版的权限控制差异较大。如果你也遇到类似的问题,首先要检查是否已勾选“采集用户隐私”,并确保在提交审核时配置了隐私条款。这个设置非常关键,避免像我一样浪费了不少时间和版本。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 1078

PAT甲级 1140 Look-and-say Sequence (20分) 字符串处理/C++

1140 Look-and-say Sequence (20分) 字符串处理 题目大意:这题和LeetCode里面的38. Count and Say(可以看看LeetCode的各种题解)差不多。只不过say和count的位置相反。 #include<iostream> //输入输出流头文件 #include<stack> //栈 #include<string>

qq_43955154的博客 326

【2026年华为暑期实习(AI)-4月29日-第一题- 选择题】(题目+思路+Java&C++&Python解析+在线测试)

本文摘要涵盖了机器学习和深度学习中的多个核心概念与技术,包括非负矩阵分解、条件数、MobileNet创新点、LDA降维、大模型评测指标、半精度训练、多任务学习、GPU存储层次、正则化、张量并行等。通过12道单选题和8道多选题的形式,系统性地考察了相关理论原理、应用场景及工程实践要点。题目设计注重概念准确性(如LDA目标函数)、技术细节(如Megatron-LM的并行策略)与实际应用(如FP16训练动机),并包含概率统计(二项分布)和数值计算(微分误差分析)等数学基础内容,全面检验读者对AI领域关键知识的掌握

m0_73659489的博客 143

innovus:ccopt_design分段长tree操作

这步don't touch保证后面完整cts尽量不会动到已经长过的tree。需要给sub tree手写一个spec,参考create_ccopt_clock_tree_spec -file的写法,只写create_ccopt_clock_tree和skew group部分就行。

m0_61544122的博客 1679

【PAT】1140 Look-and-say Sequence 最后一个测试点超时问题

1140 Look-and-say Sequence Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D112213111, … where D is in [0, 9] except 1. The (n+1)st number is a kind of description of the nth number. For example, the 2nd number

目标:NLP算法工程师 367

数据分析案例-对某宝用户评论做情感分析

目录 原始数据 绘制词云图 情感分析 原始数据 原始数据为某宝一商品的用户评论数据 绘制词云图 # coding=utf-8 import jieba import re import wordcloud import imageio # 打开需要分析词频的文本 with open('淘宝评论3.0.txt', encoding='utf-8') as f: data = f.read() # 文本预处理 :去除一些无用的字符只提取出中文出来 new_data

m0_64336780的博客 1万+

【PAT】A1140 Look-and-say Sequence (20point(s))

文章目录A1140 Look-and-say Sequence (20point(s))Input Specification:Output Specification:Sample Input:Sample Output:CodeAnalysis Author: CHEN, Yue Organization: 浙江大学 Time Limit: 400 ms Memory Limit: 64 MB...

Duke 247

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

IEM模型,地表粗糙度模拟

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

1140 Look-and-say Sequence (20 point(s))

思路: 字符串处理,识别连续的digit个数。 1140 Look-and-say Sequence (20 point(s)) Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D112213111, ... whereDis in [0, 9] except 1. The (n+1)st number is a kind of description o..

专栏 224

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

1140 Look-and-say Sequence (20 point(s))

#include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;string&gt; using namespace std; string res; int n; int main() { cin &gt;&gt; res &gt;&gt; n; for(int i = 0; i &lt; n - 1; ++i) { char...

徐伯莱 273

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

1140 Look-and-say Sequence (20point(s)) - C语言 PAT 甲级

* 每次利用前一个字符串生成下一个字符串,难点似乎在于如何确定字符数组的大小(实际上,数组大小多提交几次就能知道了(╥﹏╥))?或者是我未体会到此题的精髓? * 求大佬解答_(┐「ε:)_

有三只土豆 217

PAT_甲级_1140 Look-and-say Sequence (20point(s)) (C++)【字符串处理】

目录 1,题目描述 题目大意 2,思路 3,AC代码 4,解题过程 1,题目描述 Sample Input: 1 8 Sample Output: 1123123111 题目大意 ( 看了N遍,终于。。。)直接介绍例子吧 D D1(对1的描述:只有一个D) D111(对2的描述:一个D,一个1) D113(对3的描述:一个D,三个1) D11231...

&再见萤火虫&的博客 275

PAT(A) 1140 Look-and-say Sequence (20 point(s))

#include<bits/stdc++.h> using namespace std; int main(void){ int D, N; scanf("%d %d", &D, &N); vector<int> va, vb; va.push_back(D); for(int i = 0; i < N-1; i++){ int p1 = 0, p2 = 0; while(p1

Anpotan的博客 555

PAT 1140 Look-and-say Sequence (20point(s))(解题记录)

Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D112213111, … This problem asks to find the Nth Look-and-say sequence of a given digit. My Idea The main data structure I used is a queue Q that stores every temp.

momoomoo的博客 212

1140 Look-and-say Sequence (20 分)

Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D112213111, ... where D is in [0, 9] except 1. The (n+1)st number is a kind of description of the nth n...

x_zjudream的博客 179

1140. Look-and-say Sequence (20)

#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;algorithm&gt; using namespace std; string get_num(string &amp;s){ string sa = ""; for(int i = 0; i &lt; s.length(); i++){ ...

pacmo 461

PAT 甲级 1140 Look-and-say Sequence (20 分) 模拟

题意: 先给一个数D(看作字符串)然后每次变化时把这个字符串中 字符相同的连续一段映射成两个信息加入新的串 这两个信息为: 相同的这个字符,这个字符的数目 D -> D1 D1 -> D1 11 D111 -> D1 13 D113 -> D1 12 31 D11231-> D1...

床前明月光 257

Look and say 源码分析

Look and say 源码分析:Code: #include     #include     #include     // each subsequent element is defined from the    //previous one by "verbally"    //For exam the 

jxusthusiwen的专栏 535

【PAT】A1140 Look-and-say Sequence【字符串处理】

Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D112213111, … where D is in [0, 9] except 1. The (n+1)st number is a kind of description of the nth number....

elegant coder 1045

1140 Look-and-say Sequence (20分) 解决测试点4超时 详解

Input Specification: Each input file contains one test case, which gives D (in [0, 9]) and a positive integer N (≤ 40), separated by a space. Output Specification: Print in a line the Nth number in a look-and-say sequence of D. Sample Input: 1 8 Sample Out

weixin_43957537的博客 324
上一篇: 1114 Family Property (25 point(s))
下一篇: 1141 PAT Ranking of Institutions (25 point(s))
coderwait
博客等级 码龄9年 20粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值