数列描述

标题:数列描述 | 时间限制:1秒 | 内存限制:32768K | 语言限制:不限
有一个数列a[N] (N=60),从a[0]开始,每一项都是一个数字。数列中a[n+1]都是a[n]的描述。其中a[0]=1。


while n = STDIN.gets
  n = n.chomp.to_i
  str = '1'
  n.times {
    new_str = ''
    stack = []
    str.each_char do |char|
      if !stack.empty? && char != stack.last
        new_str += "#{stack.length}#{stack.last}"
        stack = []
      end
      stack.push(char)
    end
    new_str += "#{stack.length}#{stack.last}" if !stack.empty?
    str = new_str
    # puts str
  }
  puts str
end


全部评论

相关推荐

程序员小白条:三方不签,不就是纯实习骗人吗,还是小公司,没毛了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务