码迷,mamicode.com
首页 > 其他好文 > 详细

B - Big String

时间:2014-08-20 15:43:02      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   strong   for   ar   

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

题意:不断循环   找出第N个字母是什么  输出

        要用unsigned long long

#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

unsigned long long a[10000];
unsigned long long n;

int main()
{
    string str = "T.T^__^";
    memset(a,0,sizeof(a));
    a[0] = 4;
    a[1] = 3;
    for(int i = 2; i < 10000; i++)
        a[i] = a[i - 1] + a[i - 2];
    while(cin>>n)
    {
        while(n > 7)
        {
            int i = 0;
            while(a[i]<n)
                i++;
            n -= a[i-1];
        }
        cout<<str[n-1]<<endl;;
    }
    return 0;
}

 

B - Big String,布布扣,bubuko.com

B - Big String

标签:style   blog   color   os   io   strong   for   ar   

原文地址:http://www.cnblogs.com/zhangying/p/3924602.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!