Logo Andy0815的博客

博客

分解质因数的小代码

2024-08-08 10:45:03 By Andy0815
#include <bits/stdc++.h>
using namespace std;
const int MAX=0xfffff;
int n;
int a[MAX];
int x,y=1,p[MAX];
void pd(int n){
    for(int i=2;;i++){
        if(n==1){
            return ;
        }
        while(n%i==0){
            n/=i;
            a[++x]=i;
            p[y]++;
        }
        y++;
    }
}
int main(){
    cin >> n;
    pd(n);
    cout << n << "=";
    for(int i=1;i<=x-1;i++){
        cout << a[i] << "*";
    }
    cout << a[x];
    return 0;
}

想不想要一个帅气的王者皮肤

2023-11-19 16:34:27 By Andy0815

新幻灯片

2023-11-19 16:31:03 By Andy0815

新博客

2023-11-05 18:22:04 By Andy0815
    #include <bits/stdc++.h>
    using namespace std;
    int b;
    int x;
    int y;
    int shengren[7];
    int shengshu=7;
    void shenfen(int a){
        switch(a){
            case 1:
                cout << "必赢家" << endl;
                b=1;
                cout << "你赢了!";
                return 0; 
                break;
            case 2:
                cout << "狼人" << endl;
                b=2;
                break;
            case 3:
                cout << "平民" << endl;
                b=3;
                break;
            case 4:
                cout << "平民" << endl;
                b=4;
                break;
            case 5:
                cout << "守卫" << endl;
                b=5;
                break;
            case 6:
                cout << "平民" << endl;
                b=6;
                break;
            case 7:
                cout << "平民" << endl;
                b=7;
                break;
        }
    }
    int main(){
        cout << "下面开始抽身份";
        for(int i=1;i<=3;i++){
            Sleep(1500);
            cout << ".";
        }
        srand(time(NULL));
        int a=rand()%7+1;
        shenfen(a);
        Sleep(3000);
        while(shengshu==2&&shengren[2]!=-1){
            cout << "天黑请闭眼。";
            cout << "狼人睁眼。";
            bool f=true;
            if(b==2){
                cout << "你要刀谁?(禁止刀自己!)" << endl;
                cin >> x;
                shengren[x]=-1;
            }
            else{
                x=rand()%7+1;
                if(x==1){
                    shengren[2]=-1;
                    shengshu--;
                    x=2;
                }
                else if(x==2){
                    shengren[2]=-1;
                    shengshu--;
                    x=2;
                }
            }
            if(b==5){
                cout << "你要守护谁?" << endl;
                cin >> y;
                if(x==y){
                    shengren[x]=x;
                    f=false;
                }
            }
            cout << "天亮了。" << endl; 
            if(f){
                cout << x << "号被刀了!" << endl;
            }

        }


        return 0;
    }

二叉树笔记

2023-10-22 18:12:23 By Andy0815
//简写BT 
//在二叉树的第i层上最多有2^(i-1) 个节点 
//深度为k的二叉树最多有2^k-1 个节点 
//叶子节点的个数总比度为2的节点的个数多 1 (即:n0=n2+1)
//具有n个节点的完全二叉树的深度为(log2n)+1
//二叉树的遍历: 
//    前序遍历:1.访问根节点  2.遍历左子树  3.遍历右子树 
//    中序排列:1.遍历左子树  2.访问根节点  3.遍历右子树 
//    后序排列:1.遍历左子树  2.遍历右子树  3.访问根节点
Andy0815 Avatar