您好,欢迎来到品趣旅游知识分享网。
搜索
您的当前位置:首页3292:练47.4 小明吃苹果(C、C++、python)

3292:练47.4 小明吃苹果(C、C++、python)

来源:品趣旅游知识分享网

练47.4 小明吃苹果




 C代码:

/*
3292:练47.4 小明吃苹果
http://bas.ssoier.cn:8086/problem_show.php?pid=3292
*/
#include<stdio.h>
#include <stdlib.h>
#include <math.h>
int n;
int f(int x)
{
	if( x==0 || x==1 )
	{
		return 1;
	}
	if( x==2 )
	{
		return 2;
	}
	
	if( x==3 )
	{
		return 2;
	}
	
	return f(x-2)+f(x-3);
}

int main( )
{
	scanf("%d",&n);
	
	printf("%d",f(n));
	
	return 0;
}


C++程序:

#include <bits/stdc++.h>
using namespace std;
int n;
int f(int x){
	if(x==0||x==1)return 1;
	if(x==2)return 2;
	if(x==3)return 2;
	return f(x-2)+f(x-3);
}
int main(){
	cin>>n;
	cout<<f(n);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int f(int x){
	if( x==0 || x==1 ){
		return 1;
	}
	if( x==2 ){
		return 2;
	}

	if( x==3 ){
		return 2;
	}
	return f(x-2)+f(x-3);
}
int main( ){
	cin>>n;
	cout<<f(n);
	return 0;
}


python3代码:

def f(x):
            if x==0 or x==1:
                 return 1
            if x==2:
                 return 2
            if x==3:
                 return 2

            return f(x-2)+f(x-3)

n=int(input())

print( f(n) )






CSP-J CSP-S 初赛模拟题

2021年CSP-S初赛模拟题

洛谷2020、2021、2022 CSP-J1 CSP-S1 第1轮 初赛模拟

CSP-J CSP-S初赛第1轮模拟题(一)

CSP-J CSP-S初赛第1轮模拟题(二)

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- pqdy.cn 版权所有 赣ICP备2024042791号-6

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务