/*
解题思路:看过题就知道是要找规律的,而从下列式子中不轻易发明,
S(1)=1, //在s(n)从左往右看
S(2)=11, s(1)中有1个1;
S(3)=21, s(2)中有2个1;
S(4)=1211, s(3)中有1个2和1个1;
S(5)=111221, s(4)中有1个1、1个2和2个1;
S(6)=312211, s(5)中有3个1、2个2和1个1;
……
2012-05-04
*/
分析:
表示下面的规律不是自己发现的- -I。
摘:解题思路:看过题就知道是要找规律的,而从下列式子中不轻易发明,
S(1)=1, //在s(n)从左往右看
S(2)=11, s(1)中有1个1;
S(3)=21, s(2)中有2个1;
S(4)=1211, s(3)中有1个2和1个1;
S(5)=111221, s(4)中有1个1、1个2和2个1;
S(6)=312211, s(5)中有3个1、2个2和1个1;
……
2012-05-04
*/
#include"stdio.h"
#include"string.h"
int main()
{
char str[31][5000];
int len[31];
int num[30],k_temp;
int i,l;
int count,k;
int n;
memset(str,0,sizeof(str));
str[1][0]=1;
len[1]=1;
for(i=2;i<=30;i++)
{
count=1;
k=0;
for(l=1;str[i-1][l-1];l++)
{
if(str[i-1][l]!=str[i-1][l-1])
{
k_temp=0;
while(count)
{
num[k_temp]=count%10;
count/=10;
k_temp++;
}
k_temp--;
while(k_temp>=0)
{
str[i][k]=num[k_temp];
k++;
k_temp--;
}
str[i][k]=str[i-1][l-1];
k++;
count=1;
continue;
}
count++;
}
len[i]=k;
}
while(scanf("%d",&n),n)
{
printf("%d\n",len[n]);
}
return 0;
}