7-3 조세프 링 (25분)
#include
using namespace std;
#include
struct Node{
int data;
Node*next;
};
int main()
{
int n, m;
cin >> n >> m;
vectorres;
Node * first = new Node;
//first->next =nullptr;
Node *pre = new Node;
Node * p = new Node;
pre = first;
pre->next = p;
p = first;
if (n){
pre->data = 1;
}
for (int i = 2; i <= n; i++)
{
Node * pc = new Node;
pc->data = i;
pc->next = nullptr;
p->next = pc;
p = pc;
}
p->next = pre;
//cout << "pre->data = " << pre->data <next = "<data<< endl;
int cnt = 1;
for (auto i = pre,j = p;n; i = i->next)
{
if (cnt == m)
{
auto pr = i;
res.push_back(i->data);
//cout << i->data << " ";
j->next = i->next;
//delete pr;
n--;
cnt = 0;
}
cnt++;
j = i;
//system("pause");
}
bool tf = false;
for (auto &x : res)
{
if (tf)
cout << " ";
cout << x;
tf = true;
}
system("pause");
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
1052 Linked List Sorting(25점) 마지막 테스트 지점에서 세그먼트 오류 + 다른 사람의 코드1052 Linked List Sorting(25점) A linked list consists of a series of structures, which are not necessarily adjacent in me...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.