38. Count and Say

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

1 is read off as "one 1" or 11.
11 is read off as "two 1s" or 21.
21 is read off as "one 2, then one 1" or 1211.

Given an integer n, generate the nth sequence.

Note: The sequence of integers will be represented as a string.

说真的刚开始真不知道这道题要干什么,英语有点差~~~

当明白是什么意思的时候又发现描述起来有点问题,语文有点差~~~

生硬的描述一下吧:1被读作“1个1” 或  11;11被读作“2个1”或21;21被读作“1个2,1个1”或1211;依次这样下去,输出第n个序列。

代码如下:

 class Solution {
public:
string countAndSay(int n) {
string first = "";
for(int i = ; i < n; i++)
{
string ss = "";
int count = ;
for(int j = ; j < first.length(); j++)
{
if(first[j-] == first[j])
{
count ++;
}
else
{
ss = ss + (char)(count + '') + first[j-];
count = ;
}
}
first = ss + (char)(count + '') + first[first.length()-];
}
return first;
}
};

最新文章

  1. MR21、MR22和CK24的区别
  2. Hyper-V端口映射
  3. UOJ #149 [NOIP 2015] 子串
  4. 【PHP面向对象(OOP)编程入门教程】22.把对象串行化serialize()方法,__sleep()方法,__wakeup()方法
  5. Linux下多线程,断点续传,命令行下载工具axel
  6. MySQL常用技巧
  7. Android-The specified child already has a parent. You must call removeView() on the child&#39;s parent first.
  8. 谈谈PHP、Python与Ruby
  9. 常用mysql笔记
  10. PHP接口和抽象类的区别
  11. API接口开发简述示例
  12. 使用docker-compose搭建AspNetCore开发环境
  13. mysql简单主从复制(一)
  14. LINUX PID 1和SYSTEMD 专题
  15. Winio驱动在64位windows下无法使用的解决方法
  16. js增减日期
  17. E1. Array and Segments (Easy version)(暴力) &amp;&amp; E2. Array and Segments (Hard version)(线段树维护)
  18. n&&m and n||m 的区别
  19. Angular1.x directive(指令里的)的compile,pre-link,post-link,link,transclude
  20. 安装git之后,桌面图标出现很多的蓝色问号

热门文章

  1. 转载__直接拿来用!最火的Android开源项目(一)
  2. jquery ready 延迟
  3. 使用SVN进行项目版本管理
  4. 安装ipython import path error
  5. ruby的hash学习笔记例: 将字符串文本中的单词存放在map中
  6. EDE,DEDE网站搬家,DEDECMS搬家教程,一看就会
  7. C API 连接MYSQL
  8. [Flex] IFrame系列 —— 在flex的web应用中嵌入html的方法
  9. javascript 传递引用类型参数
  10. [POJ 1635] Subway tree systems (树哈希)