智力题,观察上一行,有几个数字。

  比如,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的更多相关文章

  1. 《Pro AngularJS》学习小结-02

    上一篇的项目只有一个单独的模板页面,加入了相应的controller,filter,使得页面上的数据能够动态的变化.现在我们开始建立并整合多个模板,加入购物车模块和结账checkout模块. 一.在页 ...

  2. C#中Length和Count的区别(个人观点)

    这篇文章将会很短...短到比你的JJ还短,当然开玩笑了.网上有说过Length和count的区别,都是很含糊的,我没有发现有 文章说得比较透彻的,所以,虽然这篇文章很短,我还是希望能留在首页,听听大家 ...

  3. js报错: Uncaught RangeError: Invalid string length

    在ajax请求后得到的json数据,遍历的时候chrome控制台报这个错误:Uncaught RangeError: Invalid string length,在stackoverflow查找答案时 ...

  4. string length() 方法注意点

    突然意识到string length() 是跟文件的字符编码相关的 测试了下, 果然如此: 对于常见字, 结果是一样的, System.out.println("T中国123".l ...

  5. String构造器中originalValue.length>size 发生的情况

    最近在看Jdk6中String的源码的时候发现String的有个这样的构造方法,源代码内容如下: public String(String original) { int size = origina ...

  6. [LeetCode] Encode String with Shortest Length 最短长度编码字符串

    Given a non-empty string, encode the string such that its encoded length is the shortest. The encodi ...

  7. [LeetCode] Length of Last Word 求末尾单词的长度

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

  8. 有关Javascript的length()函数

    刚开始学JavaScript的时候,length()对我来说是一个获取字符串长度的函数.然而前几天开始读犀牛书,得知该函数是计算字符串中16位值的个数.也就是说,对于UTF-16来说,如果包含占据了两 ...

  9. easyui Datagrid查询报错Uncaught TypeError:Cannot read property 'length' of undefined

    1.问题描述 easyui中datagrid执行loadData方法出现如下异常:Cannot read property 'length' of undefined 2.一开始怀疑是js或者页面的问 ...

随机推荐

  1. kafka基础二

    kafka生产者工作流程 消息产生分析 1.写入方式: producer采用推(push)模式将消息发布到broker,每条消息都会被追加(append)到分区Partition上,属于顺序写磁盘(顺 ...

  2. mint 有线网络未管理的解决

    sudo gedit /etc/NetworkManager/NetworkManager.conf 修改managed=true 参考链接:http://forum.ubuntu.org.cn/vi ...

  3. java mongodb-crud

    本篇文章主要介绍了mongodb对应java的常用增删改查的api,以及和spring集成后mongoTemplate的常用方法使用,废话不多说,直接上代码: 1.首先上需要用到的两个实体类User和 ...

  4. 声明已被否决 VS C++

    error C4996声明已被否决,不止一次碰到这个问题,在这里必须mark一下! 尝试这个1.Project Properties > Configuration Properties > ...

  5. ios has denied the launch request.

    ios has denied the launch request. You can choose either of the two ways. Solution 1: Open System Pr ...

  6. POJ 1741 Tree (树的分治,树的重心)

    题意:给一棵树,n个节点,给定一个数k,求任意满足dist(a,b)<=k的点对的数量. 思路: 这道题的思路比较简单,但是细节很多. 此题可以用分治法,如何分治? (1)如果path(a,b) ...

  7. 洛谷 P2419 [USACO08JAN]牛大赛Cow Contest

    题目背景 [Usaco2008 Jan] 题目描述 N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a p ...

  8. FTP的环境搭建和防火墙设置

    步骤: 1.右键点击无线网--->打开网络和共享中心--->控制面板--->程序--->启用或关闭Wondows功能

  9. Codeforces Round #317 div2 E div1 C CNF 2 (图论,匹配)

      CNF 2 'In Boolean logic, a formula is in conjunctive normal form (CNF) or clausal normal form if i ...

  10. CPP-基础:单目运算符重载

    关于++运算符前置和后置重载的实现实例: #include <iostream> using namespace std; //创建时钟类 class Clock { public: Cl ...