文章

75

粉丝

0

获赞

147

访问

8.8k

头像
猴子报数 题解:c++,采用链表方式
P1081 兰州大学/湖南大学机试题
发布于2026年2月24日 16:26
阅读数 26

#include <bits/stdc++.h>
using namespace std;

struct node{
    int num;
    node *next;
};

int main(){

    int n,s,m;
    while(cin >> n >> s >> m && (n != 0 || s != 0 || m != 0)){
        node* head = new node();
        head->next = head;
        head->num = 1;
        node* p = head;
        for(int i = 2; i <= n; i++){  //尾插法建立链表
            node* n = new node();
            n->num = i;
            n->next = p->next;
            p->next = n;
            p = n;
        }
        p = head;
        while(p->num != s){
         ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发