[ZJ]d212: 東東爬階梯
題目:
http://zerojudge.tw/ShowProblem?problemid=d212
---------------------------------------------------------------------------------
#include<cstdio>
typedef long long int LL;
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
LL a = 1, b = 2, x = a + b;
for(int i=3;i<=n;i++)
{
x = a + b;
a = b;
b = x;
}
if(n == 1)
printf("%lld\n",a);
else if(n == 2)
printf("%lld\n",b);
else
printf("%lld\n",x);
}
return 0;
}
http://zerojudge.tw/ShowProblem?problemid=d212
---------------------------------------------------------------------------------
#include<cstdio>
typedef long long int LL;
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
LL a = 1, b = 2, x = a + b;
for(int i=3;i<=n;i++)
{
x = a + b;
a = b;
b = x;
}
if(n == 1)
printf("%lld\n",a);
else if(n == 2)
printf("%lld\n",b);
else
printf("%lld\n",x);
}
return 0;
}
留言
張貼留言