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或者页面的问 ...
随机推荐
- 【Linux】VirtualBox网络配置桥接模式
VirtualBox网络配置桥接模式 CentOS/RHEL (虚拟机)配置 # 基于桥接模式设置固定 ip cat >> /etc/sysconfig/network-scripts/i ...
- ps 进程管理
一. 进程管理 1. pstree 2. ps 3. top 4. nice 5. free 6. screen 二. 程序与进程 程序是静态的文件,进程是动态运行的程序. 三. 进程和线程 一个程序 ...
- CString的GetBuffer和ReleaseBuffer
GetBuffer()主要作用是将字符串的缓冲区长度锁定,releaseBuffer则是解除锁定,使得CString对象在以后的代码中继续可以实现长度自适应增长的功能. CString ::GetBu ...
- Android实现按钮点击效果(第一次点击变色,第二次恢复)
1.首先创建一个按钮 <Button android:id="@+id/click" android:layout_width="fill_parent" ...
- python super详解
一.super() 的入门使用 - 在类的继承中,如果重定义某个方法,该方法会覆盖父类的同名方法,但有时,我们希望能同时实现父类的功能, 这时,我们就需要调用父类的方法了,可通过使用 super 来实 ...
- SQLServer查询耗时sql语句
qs.total_worker_time/qs.execution_count as [Avg CPU Time], , ( ) as query_text, qt.dbid, dbname=db_n ...
- iphone图片简单处理
使用sips批量缩放图片大小 >>sips -s format jpeg -Z 250 someImage.PNG --out myImage.JPEG 把someImage.PNG转换为 ...
- 编程中什么是「Context(上下文)」?
https://www.zhihu.com/question/26387327 每一段程序都有很多外部变量.只有像Add这种简单的函数才是没有外部变量的.一旦你的一段程序有了外部变量,这段程序就不完整 ...
- Itunes共享机制实现
http://www.raywenderlich.com/1948/itunes-tutorial-for-ios-how-to-integrate-itunes-file-sharing-with- ...
- SNP|RELP|genetic polymorphism|
5.3个体基因组呈现广泛变化 遗传多态性:一个基因座上存在多个等位基因(因为野生型不止一种基因)的现象,但是只有这多种等位基因满足:1.多个基因稳定存在2.基因在种群中数目大于1%时,认为该基因座多态 ...