hlg 1580 tell me the length
智力题,观察上一行,有几个数字。
比如,S[1]=1;
S[2]=11;
S[3]=21;
S[4]=1211;
这样就可以观察出来,序列一是1个1 ---> S[2] = 11 ;
序列二是2个1 ---> S[3] = 21 ;
序列三是1个2,2个1 ----> S[4] = 1221 ;
知道了这个规律就好办了,然后写个函数把30个序列都给写出来就行了,一开始我还准备自己在纸上把30个序列写出来呢,后来我发现不太靠谱,好长啊!!!
#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <stack>
#include <map>
#include <vector>
#include <string>
using namespace std;
/*
剩下的就是正常的代码了
-------------------------------------------------
*/
string list[];
void init()
{
list[]="";
int i,j,cnt,val,len;
string res;
string t="";
char temp;
char BREAK;
for(i=;i<=;++i){
res="";
len=list[i-].length();
cnt=;
BREAK=list[i-][];
for(j=;j<len;++j){
if(BREAK!=list[i-][j]){
t[]=''+cnt;
res=res+t;
t[]=BREAK;
res=res+t;
BREAK=list[i-][j];
cnt=;
}else{
cnt++;
}
}
t[]=''+cnt;
res=res+t;
t[]=BREAK;
res=res+t;
list[i]=res;
//cout<<list[i]<<endl;
}
return;
}
int main()
{
int n;
init();
while(cin>>n&&n){
cout<<list[n].length()-<<endl;
}
return ;
}
hlg 1580 tell me the length的更多相关文章
- 《Pro AngularJS》学习小结-02
上一篇的项目只有一个单独的模板页面,加入了相应的controller,filter,使得页面上的数据能够动态的变化.现在我们开始建立并整合多个模板,加入购物车模块和结账checkout模块. 一.在页 ...
- C#中Length和Count的区别(个人观点)
这篇文章将会很短...短到比你的JJ还短,当然开玩笑了.网上有说过Length和count的区别,都是很含糊的,我没有发现有 文章说得比较透彻的,所以,虽然这篇文章很短,我还是希望能留在首页,听听大家 ...
- js报错: Uncaught RangeError: Invalid string length
在ajax请求后得到的json数据,遍历的时候chrome控制台报这个错误:Uncaught RangeError: Invalid string length,在stackoverflow查找答案时 ...
- string length() 方法注意点
突然意识到string length() 是跟文件的字符编码相关的 测试了下, 果然如此: 对于常见字, 结果是一样的, System.out.println("T中国123".l ...
- String构造器中originalValue.length>size 发生的情况
最近在看Jdk6中String的源码的时候发现String的有个这样的构造方法,源代码内容如下: public String(String original) { int size = origina ...
- [LeetCode] Encode String with Shortest Length 最短长度编码字符串
Given a non-empty string, encode the string such that its encoded length is the shortest. The encodi ...
- [LeetCode] Length of Last Word 求末尾单词的长度
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- 有关Javascript的length()函数
刚开始学JavaScript的时候,length()对我来说是一个获取字符串长度的函数.然而前几天开始读犀牛书,得知该函数是计算字符串中16位值的个数.也就是说,对于UTF-16来说,如果包含占据了两 ...
- easyui Datagrid查询报错Uncaught TypeError:Cannot read property 'length' of undefined
1.问题描述 easyui中datagrid执行loadData方法出现如下异常:Cannot read property 'length' of undefined 2.一开始怀疑是js或者页面的问 ...
随机推荐
- IE6下png背景不透明——张鑫旭博客读书笔记
从今天开始跟着大牛张鑫旭的步伐,每天进步一点点 问题:IE6不支持png背景透明或半透明 一.可解决的方法 补充:css滤镜主要是用来实现图像的各种特殊效果.(了解) css滤镜的标识符是“filte ...
- Objective-C Loops
There may be a situation, when you need to execute a block of code several number of times. In gener ...
- 最小化安装centos后ifconfig看不到eth0
最小换安装centos后,ifconfig看不到eth0,只看到一个lo ifup eth0
- IOS照相
#import <UIKit/UIKit.h> @interface AddPictureViewController : UIViewController<UIImagePicke ...
- ycsb安装和使用介绍
nosql性能测试工具ycsb0.1的使用 使用文档参考地址:https://www.cnblogs.com/SailorXiao/p/5808828.html ycsb地址:https://gith ...
- Redis性能优化之redis.cnf配置参数
redis调优总结 1.相应的参数调优 加内存2.redis使用结构调优3.使用合理的数据类型说明:redis存储的数据为redis hash(字符映射表) 单key多字段结构. 1)调整配置文件中配 ...
- SAP云平台,Netweaver,Kubernetes和C4C的用户和角色关系
SAP云平台 Netweaver 同SAP云平台一样,在事务码PFCG里维护角色: 然后在事务码SU01里将多个角色分配给用户: Kubernetes Kubernetes在1.3版本中发布了alph ...
- decompressedResponseImageOfSize:completionHandler:]_block_invoke
原因: It turns out the linker error was caused by the CGImageSourceCreateWithData call. And the root ...
- Maven项目报错:Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clea
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) ...
- "Mac OS X"录屏幕视频并转成gif
第一步: 使用软件QuickTime Player录屏幕视频,创建方式选择新建屏幕录制: 选择区域录制,录好保存后,就需要转gif,需要另外一个软件. 第二步: 使用GIFBrewery软件创建gif ...