PAT-1140(Look-and-say Sequence)字符串处理
Look-and-say Sequence
PAT-1140
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<sstream>
using namespace std;
const int maxn=40;
int main(){
int d,n;
cin>>d>>n;
char ch='0'+d;
string now="";
now+=ch;
for(int i=1;i<n;i++){
int len=now.length();
int num=1;
string tem="";
for(int j=0;j<len-1;j++){
if(now[j]==now[j+1]){
num++;
}else{
tem+=now[j];
stringstream ss;
ss<<num;
tem+=ss.str();
num=1;
}
}
tem+=now[len-1];
stringstream ss;
ss<<num;
tem+=ss.str();
now=tem;
}
cout<<now<<endl;
return 0;
}
PAT-1140(Look-and-say Sequence)字符串处理的更多相关文章
- PAT 1140 Look-and-say Sequence [比较]
1140 Look-and-say Sequence (20 分) Look-and-say sequence is a sequence of integers as the following: ...
- PAT 1140 Look-and-say Sequence
1140 Look-and-say Sequence (20 分) Look-and-say sequence is a sequence of integers as the following ...
- [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, ...
- 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 ...
- PAT 天梯赛 L1-032. Left-pad 【字符串】
题目链接 https://www.patest.cn/contests/gplt/L1-032 思路 要分两种情况处理 ①字符串长度 <= 填充长度 就在字符串前面输出(填充长度 - 字符串长度 ...
- PAT (Advanced Level) 1051. Pop Sequence (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT (Advanced Level) 1085. Perfect Sequence (25)
可以用双指针(尺取法),也可以枚举起点,二分终点. #include<cstdio> #include<cstring> #include<cmath> #incl ...
- 【PAT甲级】1085 Perfect Sequence (25 分)
题意: 输入两个正整数N和P(N<=1e5,P<=1e9),接着输入N个正整数.输出一组数的最大个数使得其中最大的数不超过最小的数P倍. trick: 测试点5会爆int,因为P太大了.. ...
- 【PAT甲级】1051 Pop Sequence (25 分)(栈的模拟)
题意: 输入三个正整数M,N,K(<=1000),分别代表栈的容量,序列长度和输入序列的组数.接着输入K组出栈序列,输出是否可能以该序列的顺序出栈.数字1~N按照顺序随机入栈(入栈时机随机,未知 ...
- PAT(B) 1040 有几个PAT(Java)
题目链接:1040 有几个PAT (25 point(s)) 题目描述 字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位§,第 4 位(A),第 6 位(T):第二个 ...
随机推荐
- Codeforces Round #295 (Div. 2) B. Two Buttons (DP)
题意:有两个正整数\(n\)和\(m\),每次操作可以使\(n*=2\)或者\(n-=1\),问最少操作多少次使得\(n=m\). 题解:首先,若\(n\ge m\),直接输出\(n-m\),若\(2 ...
- git仓库更换远程地址
首先进入项目所在文件夹,右键git bash (1)查看当前的远程地址 git remote -v (2)删除当前的远程地址 git remote rm origin (3)添加远程地址 git re ...
- PowerShell多任务
代码 foreach ($server in $servers) { $running = @(Get-Job | Where-Object { $_.State -eq 'Running' }) i ...
- [Python] Pandas 中 Series 和 DataFrame 的用法笔记
目录 1. Series对象 自定义元素的行标签 使用Series对象定义基于字典创建数据结构 2. DataFrame对象 自定义行标签和列标签 使用DataFrame对象可以基于字典创建数据结构 ...
- kubernetes实战-配置中心(二)交付apollo配置中心到k8s
apollo官网:官方地址 apollo架构图: apollo需要使用数据库,这里使用mysql,注意版本需要在5.6以上: 本次环境mysql部署在10.4.7.11上,使用mariadb:10.1 ...
- ES索引Index相关操作&ES数据类型、字符串类型text和keyword区别
1.查看索引以及删除之前的测试索引 1. 查看索引以及索引数量信息 liqiang@root MINGW64 ~/Desktop $ curl -X GET http://127.0.0.1:9200 ...
- (转载)RTMP协议中的AMF数据 http://blog.csdn.net/yeyumin89/article/details/7932585
为梦飞翔 (转载)RTMP协议中的AMF数据 http://blog.csdn.net/yeyumin89/article/details/7932585 这里有一个连接,amf0和amf3的库, ...
- 图像处理中Stride的理解
一行有 11 个像素(Width = 11), 对一个 32 位(每个像素 4 字节)的图像, Stride = 11 * 4 = 44. 但还有个字节对齐的问题, 譬如: 一行有 11 个像素(Wi ...
- React Gatsby 最新教程
React Gatsby 最新教程 https://www.gatsbyjs.com/docs/quick-start/ https://www.gatsbyjs.com/docs/tutorial/ ...
- node.js module.exports & exports & module.export all in one
node.js module.exports & exports & module.export all in one cjs const log = console.log; log ...