3 条题解

  • 0
    @ 2022-10-01 18:02:44

    #include <iostream>
    using namespace std;
    int main()
    {
    int n,x,y;
    cin>>n>>x;
    for(int i=1;i<n;i++){
    cin>>y;
    for(int j=y;j>=1;j--){
    if (y%j==0&&x%j==0) {x=j;break;}
    }

    }
    cout<<x;

    return 0;

    }

  • 0
    @ 2022-08-08 15:33:57

    哦——鸡你太美! baby 哦——鸡你太美!……

    #include<iostream>
    using namespace std;

    struct Node
    {
    int data;
    Node *next;
    };

    class LinkList
    {
    private:
    Node *head;
    int n;//存储所有数的个数
    public:

    LinkList (int set_n)
    {
    n=set_n;
    head=NULL;

    }

    void insert()
    {

    Node *tail;
    int x;
    for(int i=0;i<n;i++)
    {
    cin>>x;
    Node *newp=new Node;
    newp->data=x;
    if(head==NULL)
    {
    head=newp; tail=newp;
    }
    else
    {
    tail->next=newp;
    tail=newp;
    }
    if(tail!=NULL)
    tail->next=NULL;
    }
    }

    int yue_shu(int a,int b)
    {
    int tmp;
    if(a<b)
    {
    tmp=a;
    a=b;
    b=tmp;
    }
    return b==0?a:yue_shu(b,a%b);
    }

    void output()
    {
    Node *p=head;
    while(p!=NULL)
    {
    cout<<p->data<<" ";
    p=p->next;
    }
    cout<<endl;
    }

    friend int get_result(LinkList &L)
    {
    Node *prev,*p;
    int sum=0;
    prev=NULL, p=L.head;
    while(p!=NULL)
    {
    if(prev==NULL)
    {
    prev=p;
    p=p->next;
    sum=L.yue_shu(prev->data,p->data);
    p=p->next;
    }
    else
    {
    sum=L.yue_shu(sum,p->data);
    p=p->next;
    }
    }
    return sum;
    }
    };

    int main()
    {
    int n;
    cin>>n;
    LinkList list(n);
    list.insert();
    cout<<get_result(list)<<endl;

    system("pause");
    return 0;
    }

  • -1
    #include<iostream>
    using namespace std;
    
    struct Node
    {
        int data;
        Node *next;
    };
    
    class LinkList
    {
    private:
        Node *head;
        int n;//存储所有数的个数
    public:
    
        LinkList (int set_n)
        {
            n=set_n;
            head=NULL;  
        }
    
        void insert()
        {       
            Node *tail;
            int x;
            for(int i=0;i<n;i++)
            {
                cin>>x;
                Node *newp=new Node;
                newp->data=x;
                if(head==NULL)
                {
                    head=newp; tail=newp;
                }
                else
                {
                    tail->next=newp;
                    tail=newp;
                }
                if(tail!=NULL)
                    tail->next=NULL;
            }
        }
    
        int yue_shu(int a,int b)
        {
            int tmp;
            if(a<b)
            {
                tmp=a;
                a=b;
                b=tmp;
            }
            return b==0?a:yue_shu(b,a%b);
        }
    
        void output()
        {
            Node *p=head;
            while(p!=NULL)
            {
                cout<<p->data<<" ";
                p=p->next;
            }
            cout<<endl;
        }
    
        friend int get_result(LinkList &L)
        {
            Node *prev,*p;
            int sum=0;
            prev=NULL, p=L.head;
            while(p!=NULL)
            {
                if(prev==NULL)
                {
                    prev=p;
                    p=p->next;
                    sum=L.yue_shu(prev->data,p->data);
                    p=p->next;
                }
                else
                {
                    sum=L.yue_shu(sum,p->data);
                    p=p->next;
                }
            }
            return sum;
        }
    };
    
    int main()
    {
        int n;
        cin>>n;
        LinkList list(n);
        list.insert();
        cout<<get_result(list)<<endl;
    
        system("pause");
        return 0;
    }
    
  • 1

A6-4 最大公约数专题:多个数的最大公约数

信息

难度
5
分类
(无)
标签
递交数
705
已通过
251
通过率
36%
被复制
7
上传者