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

3292:练47.4 小明吃苹果

信息学奥赛一本通-编程启蒙(C++版)在线评测系统

练47.4 小明吃苹果

信息学奥赛一本通-编程启蒙(C++版)在线评测系统




 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 初赛模拟题

CSP-J CSP-S 初赛模拟题_csp-j 初赛模拟卷1-10-CSDN博客

2021年CSP-S初赛模拟题

2021年CSP-S初赛模拟题-CSDN博客

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

洛谷2020、2021、2022、2023 CSP-J1 CSP-S1 第1轮 初赛模拟_2023cspj模拟题洛谷-CSDN博客

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

CSP-J CSP-S初赛第1轮模拟题(一)_csp-s 模拟-CSDN博客

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

CSP-J CSP-S初赛第1轮模拟题(二)_csp-s模拟题-CSDN博客

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dllglvzhenfeng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值