文章

6

粉丝

53

获赞

1

访问

1.6k

头像
击鼓传花 题解:主要是模拟过程 没有技巧版
P1018 贵州大学机试题
发布于2024年3月1日 20:39
阅读数 296

#include<iostream>
using namespace std;

int main(){

    struct Node {
        int n;
        struct Node * next;
    };
    int N;
    cin>>N;
    //构建循环链表
    struct Node *p,*q,*h,*t;
    p = new Node;
    h=p;
    for (int i = 1; i <=N ; i++) {
        p->n=i;
        q = new Node;
        p->next = q;
        t=p;   //记录结尾
        p=q;
    }

    t->next = h;  //形成闭环
    //从1号开始传
    p=h;
        while (h->next!=h){
//        移动两次
            p = h->next;
            q = h->next->next;
//            cout&l...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发