hdu 1sting

不看不知道算几个数出来

原来是斐波那契数列

但是他是大数所以不要大意

 

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int N=210;

int a[N][N];

void judge()
{
    int i = 0;
    int j = 0;

    a[1][0] = 1;
    a[2][0] = 2;

    for(i = 3; i < N-3; i++)
        {
            int k = 0;
            int t = 0;
            int sum = 0;

            while(k < N)
            {
                sum = a[i-2][k] + a[i-1][k] + t;
                a[i][k] = sum %10;
                t = sum / 10;
                k++;
            }
        }
}

void print(int n)
{
    int i = N-1;
    int j = 0;
    for(i = N-1; i>=0; i--)
       if(a[n][i]) break;
    for(j = i; j >=0; j--)
        printf("%d",a[n][j]);
        printf("\n");
}

int main()
{
    memset(a,0,sizeof(a));
    judge();

    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        char ch[N];
        scanf("%s",ch);
        n = strlen(ch);
        print(n);
    }
    return 0;
}

 

你可能感兴趣的:(HDU)