“伯爵说”序列如下:1,11,21,1211,111221, \ldots1,11,21,1211,111221,…。其1
读作one 1
或者11
。11
读作two 1s
或者21
。21
读作one 2, one 1
或者1211
。
输入格式
多组输入,读到文件结束。每组输入给定一个整数 n(1 \leq n \leq 30)n(1≤n≤30)。
输出格式
输出第 nn 个序列。注意,整数序列以字符串的形式表示。
样例输入
6
样例输出
312211
我这一题是用python写的,感觉方便一点。
提示是类似斐波那契,没看出来就放飞自我的写了。。
def c(s):
n = 0
c = ''
ans = ""
for str in s:
if (c == ''):
c = str
if (str == c):
n += 1
else:
ans = ans + n.__str__() + c
c = str
n = 1
ans = ans + n.__str__() + c
return ans
while True:
s = '1'
try:
n = int(input())
except:
break
while n != 1:
#print(s)
s = c(s)
n -= 1
print(s)