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<iostream>
using namespace std; int main(){
string s;
int n,j;
cin >> s;
cin >> n;
while(--n){
string ans;
int cnt = ;
char pre = s[];
for(int i = ; i < s.size(); i++){
if(s[i] == pre) cnt++;
else{
ans += pre;
ans += cnt + '';
pre = s[i];
cnt = ;
}
}
if(cnt > ){
ans += pre;
ans += cnt +'';
}
s = ans;
}
cout << s;
return ;
}
1140 Look-and-say Sequence (20 分)的更多相关文章
- 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 ...
- 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 ...
- [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, ...
- 1116 Come on! Let's C (20 分)
1116 Come on! Let's C (20 分) "Let's C" is a popular and fun programming contest hosted by ...
- pat 1116 Come on! Let's C(20 分)
1116 Come on! Let's C(20 分) "Let's C" is a popular and fun programming contest hosted by t ...
- PAT甲级:1136 A Delayed Palindrome (20分)
PAT甲级:1136 A Delayed Palindrome (20分) 题干 Look-and-say sequence is a sequence of integers as the foll ...
- 抛弃EF,20分构建一个属于自己的ORM框架
Poiuyt_cyc 博客园首页新随笔联系订阅管理随笔 - 11 文章 - 0 评论 - 111 抛弃EF,20分构建一个属于自己的ORM框架 相信EF大家都不陌生了,因为数据库表跟程序实体是一一 ...
- PTA 邻接表存储图的广度优先遍历(20 分)
6-2 邻接表存储图的广度优先遍历(20 分) 试实现邻接表存储图的广度优先遍历. 函数接口定义: void BFS ( LGraph Graph, Vertex S, void (*Visit)(V ...
- #020PAT 没整明白的题L1-009 N个数求和 (20 分)
后面的测试点过不去,两个错误一个超时. 目前未解决 L1-009 N个数求和 (20 分) 本题的要求很简单,就是求N个数字的和.麻烦的是,这些数字是以有理数分子/分母的形式给出的,你输出的和 ...
- L1-023 输出GPLT (20 分)
L1-023 输出GPLT (20 分) 给定一个长度不超过10000的.仅由英文字母构成的字符串.请将字符重新调整顺序,按GPLTGPLT....这样的顺序输出,并忽略其它字符.当然,四种字符(不区 ...
随机推荐
- 3.Hive中查看数据来源文件和具体位置方法
虚拟列 -- 当 hive 产生了非预期的或 null 的时候,可以通过虚拟列进行诊断,判断哪行数据出现问题 INPUT__FILE__NAME (输入文件名)map任务读入File的全路径 ...
- maven的pom文件解析及配置
1.IDEA中的Maven的pom.xml文件,其实比较通俗点介绍功能主要项目引入的jar包,管理配置项目以及一些插件的配置等项目 2.对于pom配置详细介绍,整理如下2篇文档介绍的比较系统全面: h ...
- EasyUI控件combobox重复请求后台,dialog窗口数据异常
最近在用Easy UI+Dapper+MVC4 开发一个财务收款系统,其中就发现一些小问题,供有需要的人参考. 1.EasyUI控件combobox 数据绑定 出现重复请求后台 上代码: <td ...
- 在构造函数和析构函数中调用虚函数------新标准c++程序设计
在构造函数和析构函数中调用虚函数不是多态,因为编译时即可确定调用的是哪个函数.如果本类有该函数,调用的就是本类的函数:如果本类没有,调用的就是直接基类的函数:如果基类没有,调用的就是间接基类的函数,以 ...
- vs2015+opencv3.3.1 实现 c++ 直方图均衡化
//直方图均衡化 https://github.com/scutlzk #include <opencv2\highgui\highgui.hpp> #include <iostre ...
- NSArray 数组
前言 数组只能存储 OC 对象,不能存储 C 语言中的基本数据类型,也不能存储 nil . Xcode 7 对系统中常用的一系列容器类型都增加了泛型支持(),有了泛型后就可以指定容器类中对象的类型了. ...
- svn: Can’t convert string from ‘UTF-8’ to native encoding: 解决办法
主要原因是linux的编码发生改动 只需该为 en_US.UFT-8即可 [具体操作可以查看]https://www.cnblogs.com/sz-xioabai/p/10523423.html
- PTA数据结构之 List Leaves
Given a tree, you are supposed to list all the leaves in the order of top down, and left to right. I ...
- javascript前端导出csv表格
使用场景 后台统计经常要展示各种各样的表格数据,几乎每个表格展示都会伴随着数据的导出. 之前的解决方案都是通过发起一个相同查询参数(querystring)的导出请求(action=export),由 ...
- 【BZOJ2839】集合计数 容斥原理+组合数
Description 一个有N个元素的集合有2^N个不同子集(包含空集),现在要在这2^N个集合中取出若干集合(至少一个),使得 它们的交集的元素个数为K,求取法的方案数,答案模1000000007 ...