zoj1633Big String

Big String

Time Limit: 2 Seconds       Memory Limit: 65536 KB

We will construct an infinitely long string from two short strings: A = "^__^" (four characters), and B = "T.T" (three characters). Repeat the following steps:
  • Concatenate A after B to obtain a new string C. For example, if A = "^__^" and B = "T.T", then C = BA = "T.T^__^".
  • Let A = B, B = C -- as the example above A = "T.T", B = "T.T^__^".
Your task is to find out the n-th character of this infinite string.


Input

The input contains multiple test cases, each contains only one integer N (1 <= N <= 2^63 - 1). Proceed to the end of file.


Output

For each test case, print one character on each line, which is the N-th (index begins with 1) character of this infinite string.


Sample Input

1
2
4
8


Sample Output

T
.
^
T
斐波那契字符问题,但是若是一直求字符串并直接输出,很显然不现实,因为数组不可能开那么大。所以就运用递归循环来做,找到所输入的数字是按照题目要求的斐波那契的第几位,减去其前边的,一直减到不能见位置,在对应输出就行了:
附代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long int n;
int main()
{
	char base[]="T.T^__^\0";
	long long f[88];
	f[0]=7;
	f[1]=10;
	for(int i=2;i<88;i++)
	f[i]=f[i-1]+f[i-2];
	while(scanf("%lld",&n)!=EOF)
	{
		while(n>7)
		{
			int i=0;
			while(i<88&&f[i]<n)
			i++;
			n-=f[i-1];
		}	
		printf("%c\n",base[n-1]);
	}
	return 0;
}
 


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值