当前位置:网站首页>测试第二题
测试第二题
2022-07-30 05:46:00 【缘聚654】
题目描述
楼梯有 NN 阶,上楼可以一步上一阶,也可以一步上二阶。
编一个程序,计算共有多少种不同的走法。
输入格式
一个数字,楼梯数。
输出格式
输出走的方式总数。
输入输出样例
输入 #1复制
4
输出 #1复制
5
说明/提示
- 对于 60\%60% 的数据,N \leq 50N≤50;
- 对于 100\%100% 的数据,1 \le N \leq 50001≤N≤5000。
#include <stdio.h> int a[10000]={0};//a,b,c存放每一位数,进行轮加 int b[10000]={0}; int c[10000]={0}; int main() { int temp; int k; int wei=1; b[0]=1;//斐波那契数列初始 c[0]=2; int n; int i,j; scanf("%d",&n); if(n==1)//1,2排除在外 { printf("%d\n",1); } else if(n==2) { printf("%d\n",2); } else { for(k=0;k<n-2;k++) { for(i=0;i<wei;i++) { a[i]=b[i]+c[i];//先让每一位相加置于a中 } temp=0; for(i=0;i<wei;i++)//进位操作 { j=a[i]+temp; a[i]=j%10; temp=j/10; } if(temp>0)//判断最后是否需要进位 { a[i]=temp; wei++; } for(i=0;i<wei;i++)//轮换 { b[i]=c[i]; c[i]=a[i]; } } for(i=wei-1;i>=0;i--) { printf("%d",a[i]);//a,b,c均是反向存数,因此逆向输出 } } }4 5 ---------
边栏推荐
猜你喜欢

Explore the efficiency of make_shared

数码管动态显示及模块化编程

Diwen serial screen production (serialization 1) ===== preparation work

2021 soft exam intermediate pass

This beta version of Typora is expired, please download and install a newer; workaround

QT serial port dynamically displays a large number of data waveform curves in real time (5) ======== "Final perfect solution version"

Cannnot download sources不能下载源码百分百超详细解决方案

Acwing Brush Questions Section 1

FPGA parsing B code----serial 2

与所有 ARM 工具、软件兼容?韦斯佰瑞这款MCU内核值得关注!
随机推荐
Massive remote sensing data processing and application of GEE cloud computing technology [basic, advanced]
高集成度 MCU 市场增大,如何加速 BLDC 领域落地应用
2020-09-03 Solve the very slow installation of pip install [Errno 101] Network unreachable problem
QT Weekly Skills (1) ~~~~~~~~~ Running Icon
[Jiangsu University Automation Association stm32F103c8t6] Notes [Initial 32 MCU and EXTI External Interrupt Initialization Parameter Configuration]
ssh 脚本 空格字符转换
Insertion Sort in Classic Sort
电子工程师怎么才能规范设计标准、提高设计效率?
"R Language + Remote Sensing" Comprehensive Evaluation Method of Water Environment
闭包(你不知道的JS)
二进制到汇编:进制,原码反码补码,位运算,通用寄存器,内存一套打通
TCP建立连接的过程
js高级学习笔记(详细)
Kunlun State Screen Production (Serialization 5) --- Basics (serial port reception, text and light display)
ipconfig Command Guide
Cannnot download sources不能下载源码百分百超详细解决方案
QT serialization 1: readyRead() function, the solution to incomplete data subcontracting
无法完成包的安装npm ERR! Refusing to install package with name “moment“ under a package also called “moment“
ES6语法笔记(ES6~ES11)
Anaconda 安装低版本tensorflow