C++

 class Solution {
public:
/**
* @param n the nth
* @return the nth sequence
*/
string countAndSay(int n) {
// Write your code here
if ( == n) {
return "";
}
string pre = "";
for (int i = ; i < n; i++) {//从第2个(i=1)开始
char ch = pre[];
string cur = "";
int cnt = ;
for (int j = ; j < pre.size(); j++) {
if (pre[j] == ch) {
cnt ++;
} else {
cur = cur + itostr(cnt) + ch;
ch = pre[j];
cnt = ;
}
}
if (cnt != ) {//处理后边的字符
cur = cur + itostr(cnt) + ch;
}
pre = cur;
cur = "";
}
return pre; }
string itostr(int i) {//自定义int转string函数
char str[];
//itoa(str,i,10);->only support Windows
sprintf(str, "%d", i);//support any platforms
return str;
}
};

LintCode: Count and Say的更多相关文章

  1. [LintCode] Count and Say 计数和读法

    The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221 ...

  2. Lintcode: Count of Smaller Number

    Give you an integer array (index from 0 to n-1, where n is the size of this array, value from 0 to 1 ...

  3. LintCode "Count of Smaller Number before itself"

    Warning: input could be > 10000... Solution by segment tree: struct Node { Node(), left(nullptr), ...

  4. LintCode Count 1 in Binary

    知识点 1. 整数的二进制表示法 2. 十进制和二进制的转换 http://baike.baidu.com/view/1426817.htm 3. 负整数的表示(原码,补码,反码) http://ww ...

  5. LeetCode "Count of Smaller Number After Self"

    Almost identical to LintCode "Count of Smaller Number before Self". Corner case needs to b ...

  6. nodejs api 中文文档

    文档首页 英文版文档 本作品采用知识共享署名-非商业性使用 3.0 未本地化版本许可协议进行许可. Node.js v0.10.18 手册 & 文档 索引 | 在单一页面中浏览 | JSON格 ...

  7. LintCode 391: Count Of Airplanes

    LintCode 391: Count Of Airplanes 题目描述 给出飞机的起飞和降落时间的列表,用 interval 序列表示. 请计算出天上同时最多有多少架飞机? 样例 对于每架飞机的起 ...

  8. lintcode :Count and Say 报数

    题目: 报数 报数指的是,按照其中的整数的顺序进行报数,然后得到下一个数.如下所示: 1, 11, 21, 1211, 111221, ... 1 读作 "one 1" -> ...

  9. lintcode :Count 1 in Binary 二进制中有多少个1

    题目: 二进制中有多少个1 49% 通过 计算在一个 32 位的整数的二进制表式中有多少个 1. 样例 给定 32 (100000),返回 1 给定 5 (101),返回 2 给定 1023 (111 ...

随机推荐

  1. springboot之异步调用@Async

    原文:http://www.cnblogs.com/xuwenjin/p/8858050.html 引言: 在Java应用中,绝大多数情况下都是通过同步的方式来实现交互处理的:但是在处理与第三方系统交 ...

  2. C# String.split()用法小结

    第一种方法 string s=abcdeabcdeabcde; string[] sArray=s.Split('c') ; foreach(string i in sArray) Console.W ...

  3. Java POI 3.17写入、导入EXCEL性能测试

    我们先测试一下写入 50000 条 程序源码: 写入的excel文件信息 再看一下文件的结构 我们再次测试一下导入数据库的性能(用移动的网络上传至电信服务器): 在导入的过程中也可以中止导入行为: 上 ...

  4. 权力的游戏第一季/全集Game of Thrones迅雷下载

    <权力的游戏>是一部中世纪史诗奇幻题材的电视连续剧,该剧以美国作家乔治·R·R·马丁的奇幻巨作<冰与火之歌>七部曲为基础改编创作. 故事背景中虚构的世界,分为两片大陆:位于西面 ...

  5. Mac下启动AndroidStudio失败

    系统环境: OSX Yosemite 10.10.1 (14B25) JAVA版本:1.8.0_11 Android Studio 版本:1.0.1 问题:Android Studio was una ...

  6. Android 代码实现应用强制装到手机内存

    在Froyo(android 2.2,API Level:8)中引入了android:installLocation.通过设置该属性可以使得开发者以及用户决定程序的安装位置. android:inst ...

  7. Android性能优化工具之Systrace

    本文大部分内容来自:http://www.androidperformance.com/android-performance-tools-systrace-1.html?utm_source=tui ...

  8. centos7更改为启动桌面或命令行模式

    进入cenos7的命令行模式 终端输入“init 3”回车进入命令行模式 登录成功后 # systemctl get-default //获取当前系统启动模式 查看配置文件 # cat /etc/in ...

  9. SpringBoot 项目中使用velocity模板(转载)

    (不要使用这种模板了,spring boot最新版已经不支持了.使用FreeMarker吧:http://blog.csdn.net/clementad/article/details/5194262 ...

  10. 轻松看懂Java字节码

    java字节码 计算机只认识0和1.这意味着任何语言编写的程序最终都需要经过编译器编译成机器码才能被计算机执行.所以,我们所编写的程序在不同的平台上运行前都要经过重新编译才能被执行. 而Java刚诞生 ...