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 <iostream>
using namespace std;
string coun(string str){
string res="";int coun=;
for(int i=;i<str.length();i++){
if(str[i]==str[i-]) coun++;
else {
res+=(str[i-]);
res+=(coun+'');
coun=;
}
}
res+=str[str.length()-];res+=(coun+'');
return res;
}
int main()
{
string A;int B;
cin>>A>>B;
for(int i=;i<B;i++) A=coun(A);
cout<<A;
system("pause");
return ;
}

PAT Advanced 1140 Look-and-say Sequence (20 分)的更多相关文章

  1. PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...

  2. PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...

  3. PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642 题目描述: Being unique is so important to peo ...

  4. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642 题目描述: A reversible prime in any n ...

  5. PAT (Advanced Level) Practice 1152 Google Recruitment (20 分)

    In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...

  6. PAT Advanced 1058 A+B in Hogwarts (20 分)

    If you are a fan of Harry Potter, you would know the world of magic has its own currency system -- a ...

  7. PAT Advanced 1031 Hello World for U (20 分)

    Given any string of N (≥) characters, you are asked to form the characters into the shape of U. For ...

  8. PAT (Advanced Level) Practice 1120 Friend Numbers (20 分) (set)

    Two integers are called "friend numbers" if they share the same sum of their digits, and t ...

  9. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分)

    A reversible prime in any number system is a prime whose "reverse" in that number system i ...

  10. PAT甲级:1136 A Delayed Palindrome (20分)

    PAT甲级:1136 A Delayed Palindrome (20分) 题干 Look-and-say sequence is a sequence of integers as the foll ...

随机推荐

  1. LNMP V1.4正式版本安装及新增Let's Encrypt一键安装和其他功能

    军哥的LNMP一键安装包已经有一些年头了,着实给需要在Linux VPS.服务器中安装WEB环境的用户提供不小的帮助,而且每年儿童节都会有较大版本的更新和升级.老左在二月份的时候有体验过LNMP V1 ...

  2. OneNote2016代码高亮插件的安装与使用

    OneNote2016代码高亮插件的安装与使用 使用效果 我觉得CSDN和博客园上面的许多讲解都不是很清晰,最后还是我自己弄好的.这里分享一下: 第一步要确认自己OneNote的版本是32位的还是64 ...

  3. 【数据库开发】Redis key-value内存数据库介绍

    Redis是一个开源的,先进的 key-value 存储可用于构建高性能,可扩展的 Web 应用程序的解决方案.Redis官方网网站是:http://www.redis.io/,如下: Redis 有 ...

  4. jquery获得 url的变量

    (function($){ $.extend({ urlGet:function () { var aQuery = window.location.href.split("?") ...

  5. Linux系统目录的学习

    1.在公司中linux 都是没有界面 2.系统路径    2.1 /表示根目录    2.2 ~表示/root    2.3etc:存放系统配置文件    2.4 home  除了root 以外所有用 ...

  6. [CF369E]Valera and Queries_离线_树状数组

    Valera and Queries 题目链接:codeforces.com/problemset/problem/369/E 数据范围:略. 题解: 这种题,就单独考虑一次询问即可. 我们发现,包括 ...

  7. Appium+python启动虚拟机上的app

    查看appPackage和appActivity方法: 1.先在cmd命令行输入  adb logcat ActivityManager:I *:s 2.点击虚拟机启动app即可查看,/前是appPa ...

  8. 1.1Spring Boot 环境配置和常用注解

    Spring Boot常用注解:@Service: 注解在类上,表示这是一个业务层bean@Controller:注解在类上,表示这是一个控制层bean@Repository: 注解在类上,表示这是一 ...

  9. Word、Excel、PPT 2016、2013、2010、2007 没有保存或断电导致文件丢失怎么恢复?

    1. 前言 没有保存文档还能恢复吗?死机.断电.蓝屏导致来不及保存文档,还能恢复吗?答案当然是可以的!Office中本身就有恢复文档的功能,可以帮助我们最大化的挽回损失. Office2013与Off ...

  10. Centos安装 k8s

    ### 一. 安装docker 1.安装依赖包```shellsudo yum install -y yum-utils device-mapper-persistent-data lvm2 ``` ...