hdu4148

/*

分析:

    表示下面的规律不是自己发现的- -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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值