文章
79
粉丝
221
获赞
46
访问
198.3k
#include <iostream>
using namespace std;
typedef struct Node {
int data;
struct Node* next;
}Node, * List;
int main() {
int n, s, m;
while (cin >> n >> s >> m) {
if (n == 0)
break;
List L = new Node;
Node* p = L, * beg = L, * begpre = L;
for (int i = 1; i <= n; i++) {
p->data = i;
if (i == s - 1)
begpre = p;
if (i == s)
beg = p;
if (i == n) {
p->next = L;
break;
}
p->next = new Node;
p = p->next;
}
int sum = 1;
if (s == 1)
begpre = p;
while (begpre != beg) {
sum++;
begpre = beg;
beg = beg->next;
if (sum == m) {
sum = 1;
cout << beg->data << ",";
begpre->next = beg->next;
free(beg);
beg = begpre->next;
}
}
cout << beg->data << endl;
free(beg);
}
return 0;
}
需要注意:
登录后发布评论
暂无评论,来抢沙发