1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
小壁灯上楼梯
#include <iostream>
using namespace std;
int a(int c){
    if(c<=2){
        return c;
    }else{
        return a(c-1)+(c-2);
    }
}
int main(int argc, char** argv) {
    int c,k;
    cin>>c;
    cout<<a(c);
    return 0;
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
求阶乘
#include <iostream>
using namespace std;
int s(int n){
    if(n<=2){
        return n;
    }else{
        return n*s(n-1);
    }
}
int main(){
    int n;
    cin>>n;
    cout<<s(n);
    return 0;
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
求最大公因数
#include <iostream>
using namespace std;
int i(int w,int k){
    if(w%k==0){
        return k;
    }else{
        return i(k,w%k);
    }
     
}
int main(int argc, char** argv) {
    int w;
    int k;
    cin>>w>>k;
    cout<<i(w,k);
    return 0;
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
地盘划分
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
long long a,b,c,s=0;
int main(){
    scanf("%lld",&a);
    scanf("%lld",&b);
    while(a>1){
        if(b>a){c=a;a=b;b=c;}
        s+=a/b;
        a%=b;
    }
    if(a!=0){s+=b;}
    printf("%lld",s);
    return 0;
}

  

posted on   黛玉醉打将门神  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示