PAT_A1140#Look-and-say Sequence
Source:
Description:
Look-and-say sequence is a sequence of integers as the following:
D, D1, D111, D113, D11231, D112213111, ...
where
Dis 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 oneDin the 1st number, and hence it isD1; the 2nd number consists of oneD(corresponding toD1) and one 1 (corresponding to 11), therefore the 3rd number isD111; or since the 4th number isD113, it consists of oneD, two 1's, and one 3, so the next number must beD11231. This definition works forD= 1 as well. Now you are supposed to calculate the Nth number in a look-and-say sequence of a given digitD.
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
Keys:
- 简单模拟
Attention:
- 这种小题有时候还挺头疼的-,-
- to_string()
Code:
/*
Data: 2019-05-24 10:44:34
Problem: PAT_A1140#Look-and-say Sequence
AC: 17:49 题目大意:
观察并说出相应的序列;
比如给出第一个数字D,第二个数字为D1(D有1个)
第三个数字为D111(D有1个,1有1个);
第四个数字为D113(D有1个,1有3个);
以此类推....
输入:
初始数字D,和轮次N
输出:
第N轮相应的序列
*/
#include<cstdio>
#include<string>
#include<iostream>
using namespace std; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n;
string s;
cin >> s >> n;
for(int k=; k<n; k++)
{
string t="";
for(int i=; i<s.size(); i++)
{
int cnt=;
while(i+<s.size() && s[i]==s[i+])
{
cnt++;
i++;
}
t += (s.substr(i,)+to_string(cnt));
}
s=t;
}
cout << s; return ;
}
PAT_A1140#Look-and-say Sequence的更多相关文章
- oracle SEQUENCE 创建, 修改,删除
oracle创建序列化: CREATE SEQUENCE seq_itv_collection INCREMENT BY 1 -- 每次加几个 STA ...
- Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等
功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...
- DG gap sequence修复一例
环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列
Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...
- [LeetCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
随机推荐
- EPEL reporsitory
在centos 5上yum install git的时候报错说没有git这个package. 这是因为centos的软件策略非常保守,因为它基本就是redhat企业版的copy.所以想在centos5 ...
- HDU 5225
求逆序的个数.首先处理出对n个数它所有排列的逆序的个数.然后,按位枚举,当枚举的数少于当前位,逆序数的个数就是前面确定的数对于后面数的逆序总数+后面k个数的排列的逆序总数. 1Y. #include& ...
- HDU1010-奇偶剪枝(DFS)
题目链接:Tempter of the Bone 第一次做剪枝的题目,剪枝,说实话研究的时间不短.好像没什么实质性的进展,遇到题目.绝对有会无从下手的感觉,剪枝越来越神奇了. .. . HDU1010 ...
- 【Ubuntu QQ】记如何在Ubuntu上安装QQ(附下载)
什么困扰着一批批的ubuntu桌面用户?是麻花藤.哦不,是QQ,怎么在ubuntu上安装完美无瑕的QQ. 最佳解决方案在“三”部分,当然前两个也不失为解决方案 一.尝试的开始 配置: 双系统:Wind ...
- Windows热键注册的底层原理
要像系统注册一个全局热键,需要用到RegisterHotKey,函数用法如下(MSDN):BOOL RegisterHotKey( ...
- C# 数据库备份与还原 小妹做了一个winform系统,需要对sql2000数据库备份和还原(小妹妹你太狠了)
成功了,把代码帖出来给大家看看,跟我刚开始帖出来的差不多,是需要杀掉进程的,我之前调用的存储过程,可能有点问题,现在改成sql了/// <summary> /// 数据库 ...
- bzoj 1059 [ ZJOI 2007 ] 矩阵游戏 —— 二分图匹配
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1059 每一列选出一个占据一行才可以: 挫败. 代码如下: #include<iostr ...
- 云-阿里云-OSS:对象存储 OSS
ylbtech-云-阿里云-OSS:对象存储 OSS 对象存储服务(Object Storage Service,OSS)是一种海量.安全.低成本.高可靠的云存储服务,适合存放任意类型的文件.容量和处 ...
- 79.员工薪水报表 Extjs 页面
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" ...
- 3.2 手机中的数据库——SQLite
http://www.sqlite.org/download.html 截至我安装SQLite数据库为止的时间,最新的版本可以下载sqlite-dll-win64-x64-3200000.zip和sq ...