-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10334.cpp
62 lines (62 loc) · 963 Bytes
/
10334.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<string.h>
#include<stdio.h>
int main()
{
char *fibo[5001]={0};
fibo[0]="4";
fibo[1]="7";
int l1=strlen(fibo[0]);
int l2=strlen(fibo[1]);
int l;
for(long i=2;i<=1000;i++)
{
char str[10000];
if(l1>=l2)
l=l1;
else l=l2;
int ca=0;
long j,k,m,p;
for(j=l1-1,k=l2-1,m=0,p=0;p<l;j--,k--,m++,p++)
{
int s1;
if(j<0)
fibo[i-2][j]='0';
s1=fibo[i-2][j]-48;
int s2;
if(k<0)
fibo[i-1][k]='0';
s2=fibo[i-1][k]-48;
int ans=0;
ans+=s1+s2+ca;
if(ans>9)
{
str[m]=(ans-10)+48;
ca=1;
}
else
{
str[m]=ans+48;
ca=0;
}
}
if(ca>0)
{
str[m]=ca+48;
m++;
}
str[m]='\0';
fibo[i]=new char[m+1];
long y=0;
for(long x=m-1;x>=0;x--,y++)fibo[i][y]=str[x];
fibo[i][y]='\0';
l1=strlen(fibo[i-1]);
l2=strlen(fibo[i]);
}
int n;
while(scanf("%d",&n)!=EOF)
{
n=n+2;
printf("%s\n",fibo[n]);
}
return 0;
}