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 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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; int main(){
string s;
cin >> s;
int n;
cin >> n;n--; while(n--){
string temp = "";
for(int i=;i < s.size();){
int j = i;
while(s[i] == s[j]&&j < s.size()){
j++;
}
temp += s[i]+to_string(j-i);
i = j;
}
s = temp;
}
cout << s; return ;
}

——这题意我也是醉了,完全没说清楚,还把人误导用map,看了题解才知道啥意思。



PAT 1140 Look-and-say Sequence的更多相关文章

  1. PAT 1140 Look-and-say Sequence [比较]

    1140 Look-and-say Sequence (20 分) Look-and-say sequence is a sequence of integers as the following: ...

  2. [PAT] 1140 Look-and-say Sequence(20 分)

    1140 Look-and-say Sequence(20 分)Look-and-say sequence is a sequence of integers as the following: D, ...

  3. PAT 解题报告 1051. Pop Sequence (25)

    1051. Pop Sequence (25) Given a stack which can keep M numbers at most. Push N numbers in the order ...

  4. PAT (Advanced Level) 1051. Pop Sequence (25)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  5. PAT (Advanced Level) 1085. Perfect Sequence (25)

    可以用双指针(尺取法),也可以枚举起点,二分终点. #include<cstdio> #include<cstring> #include<cmath> #incl ...

  6. 【PAT甲级】1085 Perfect Sequence (25 分)

    题意: 输入两个正整数N和P(N<=1e5,P<=1e9),接着输入N个正整数.输出一组数的最大个数使得其中最大的数不超过最小的数P倍. trick: 测试点5会爆int,因为P太大了.. ...

  7. 【PAT甲级】1051 Pop Sequence (25 分)(栈的模拟)

    题意: 输入三个正整数M,N,K(<=1000),分别代表栈的容量,序列长度和输入序列的组数.接着输入K组出栈序列,输出是否可能以该序列的顺序出栈.数字1~N按照顺序随机入栈(入栈时机随机,未知 ...

  8. PAT Advanced 1140 Look-and-say Sequence (20 分)

    Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D112213 ...

  9. PAT甲级——1140.Look-and-say Sequence (20分)

    Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D112213 ...

随机推荐

  1. gcc Build-in functions

    https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html gcc -posix -E -dM - </dev/null

  2. 8小时入门Git之团队合作学习记录

    Git几个重要的区域 工作流程

  3. c# 调用RDP和SSH实现远程登陆

    1.ssh的登陆实现: windows平台可以安装OpenSSHforWindows 后,可以通过cmd 执行ssh的指令. 也可以在c#编程中实现ssh的登陆: var p = new System ...

  4. 软件目录结构规范(以python为例)

    为什么要设计好目录结构   "设计项目目录结构",就和"代码编码风格"一样,属于个人风格问题.对于这种风格上的规范,一直都存在两种态度: 一类同学认为,这种个人 ...

  5. iOS进阶之UDP代理鉴权过程

    上一篇介绍的是TCP代理的鉴权过程,这篇将介绍UDP代理的大致鉴权过程. 在UDP鉴权过程中,有几点是需要注意的.首先,UDP是一种无连接协议,不需要连接,使用广播的方式:其次,为了通过鉴权,所以需要 ...

  6. 51行代码实现简单的PHP区块链

    本文原始地址:php区块链demo 今年区块链特别火,我也很火啊.我火什么呢.前几年,公众平台出现,还得花时间去学去看,后来小程序出现,又得花时间精力去学去看.现在比特币.以太坊等去中心化货币带起了区 ...

  7. js 获取链接参数的方法

    方法1: /** * 获取链接上的参数 * string 需要获取的参数名称 */ var getHref = function(string){ var reg = new RegExp(" ...

  8. 拒绝QQ空间-手把手教你美化博客

    为什么要美化? 博客园的主题看起来是有一些年代感了,应该是不符合当代大学生的审美了,起码我就觉得不行,所以我们要进行一些美化,但是搞技术的人的博客不应该搞得花里胡哨,最好是简洁一些(个人想法),网上有 ...

  9. log4J日志框架

    log4j的配置:log4j是一个日志输出框架,就是用于输出日志的,主流框架大部分都是Log4j输出.Spring框架也可以通过Log4j输出日志 Log4j提供了强大的日志输出的自定义功能(1)通过 ...

  10. 【Alpha】Scrum Meeting 9

    目录 前言 任务分配 燃尽图 会议照片 签入记录 困难 前言 第9次会议于4月13日20:00在一公寓3楼召开. 交流确认了任务进度,对下一阶段任务进行分配.时长20min. 任务分配 姓名 当前阶段 ...