米子加油


私信TA

用户名:dotcpp0678296

访问量:575

签 名:

冲冲冲

等  级
排  名 3030
经  验 1997
参赛次数 0
文章发表 14
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

解题思路:

注意事项:

参考代码:

#include <iostream>

using namespace std;


struct Node

{

int data;

Node* next, * prev;

}a[1001], * head, * tail;


int main()

{

int n; head = tail = NULL;

cin >> n;

for (int i = 1; i <= n; i++)

{

a[i].data = i;

if (head == NULL)

{

head = tail = &a[i];

}

else

{

tail->next = &a[i];

a[i].prev = tail;

tail = &a[i];

}

}

tail->next = head;

head->prev = tail;

Node* p = tail;

int count = 0;

while (1)

{

p = p->next;

++count;

if (count == 3)

{

if (p == p->next)

{

break;

}

Node* x = p->prev; Node* y = p->next;

x->next = y;

y->prev = x;

p = x;

count = 0;

}

}

cout << p->data;

return 0;

}


 

0.0分

1 人评分

  评论区