现在的位置: 首页 > 综合 > 正文

HDU 1715

2013年08月02日 ⁄ 综合 ⁄ 共 568字 ⁄ 字号 评论关闭
#include <iostream>
#include <string>
using namespace std;

string add(string s1,string s2)
{
    if(s1==""&&s2=="") return "0";
    if(s1=="") return s2;
    if(s2=="") return s1;
    int j,l,la,lb;
    string max,min;
    max=s1;min=s2;
    if(s1.length()<s2.length()) {max=s2;min=s1;}
    la=max.size();lb=min.size();
    l=la-1;
    for(j=lb-1;j>=0;j--) max[l--] += min[j]-'0'; 
    for(j=la-1;j>=1;j--) if(max[j]>'9'){max[j]-=10;max[j-1]++;}
    if(max[0]>'9') {max[0]-=10;max='1'+max;}
    return max;
}

int main()
{
    string f[1001];
    f[1]=f[2]="1";
    for(int i=3;i<=1000;i++)
        f[i]=add(f[i-1],f[i-2]);
    int n,d;
    while(cin>>n)
    {
        while(n--)
        {
            cin>>d;
            cout<<f[d]<<endl;
        }
    }
    return 1;
}

 

【上篇】
【下篇】

抱歉!评论已关闭.