View Code of Problem 108

#include<stdio.h>
#include <string.h>
//二刷  
long long dp[51]; //用int不够用 
void Initial(){
	dp[0] = 1;
	dp[1] = 2;
	for(int i=2; i<51; i++){
		dp[i] = dp[i-1] + dp[i-2];
	}
	return;
} 

int main(){
	Initial();
	int n;
	scanf("%d", &n);
	char num[51];
	for(int i=0; i<n; i++) {
		scanf("%s", num);
		int len = strlen(num);
		printf("%lld\n", dp[len-1]); //一位数字对应的是dp[0], 两位数字对应的是dp[1]
	}
	return 0;
}
     

Double click to view unformatted code.


Back to problem 108