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):第二个 ...
随机推荐
- HDU - 2825 Wireless Password (AC自动机+状压DP)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2825 题意:给一些字符串,构造出长度为n的字符串,它至少包含k个所给字符串,求能构造出的个数. 题解: ...
- 【hdu 1573】X问题(数论--拓展欧几里德 求解同余方程组的个数)
题目:求在小于等于N的正整数中有多少个X满足:X mod a[0] = b[0], X mod a[1] = b[1], X mod a[2] = b[2], -, X mod a[i] = b[i] ...
- 【uva 10048】Audiophobia(图论--Floyd算法)
题意:有一个N点M边的无向带权图,边权表示路径上的噪声值.有Q个询问,输出 x,y 两点间的最大噪声值最小的路径的该值.(N≤100,M≤1000,Q≤10000) 解法:N值小,且问多对点之间的路径 ...
- BKDR字符串哈希
BKDR字符串哈希 bkdrhash冲突的可能性非常小,但是由于\(hash\)值非常大不能映射到哈希数组地址上,所以可以通过取余,用余数作为索引地址.但这样做造成了可能的地址冲突. #include ...
- HttpClient客户端网络编程——高可用、高并发
本文是HttpClient的学习博客,RestTemplate是基于HttpClient的封装,feign可基于HttpClient进行网络通信. 那么作为较底层的客户端网络编程框架,该怎么配置使其能 ...
- Kubernets二进制安装(10)之部署主控节点部署调度器服务kube-scheduler
Kubernetes Scheduler是一个策略丰富.拓扑感知.工作负载特定的功能,调度器显著影响可用性.性能和容量.调度器需要考虑个人和集体的资源要求.服务质量要求.硬件/软件/政策约束.亲和力和 ...
- 【非原创】codeforces 1060E Sergey and Subway 【树上任意两点距离和】
学习博客:戳这里 本人代码: 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 con ...
- 2018ACM上海大都会赛 F Color it【基础的扫描线】
题目:戳这里 题意:有n*m个点全为白色,q个圆,将q个圆内所有的点都染成黑色,问最后剩下多少白色的点. 解题思路:每一行当做一个扫描线,扫描所有的圆,记录每一行在圆中的点即可,O(n*q). 附ac ...
- 计量经济学导论10:ARIMA模型
目录 ${\rm ARIMA}$ 模型 滞后算子 ${\rm MA}(q)$ 模型 ${\rm MA}(1)$ 模型 ${\rm MA}(q)$ 模型 ${\rm AR}(p)$ 模型 ${\rm A ...
- PM2 & nodemon
PM2 & nodemon node.js server tools PM2 https://pm2.keymetrics.io/ https://pm2.io/ $ yarn global ...