ccf-csp 201712-2 游戏
#include <bits/stdc++.h>
using namespace std;
int n,k;
struct node{
int number;
node *next;
};
void create(node *head,int n){
node *p = head;
for(int i=2;i<=n;i++){
node *q = new node;
q->number = i;
p->next = q;
p=q;
}
p->next=head;
}
int main()
{
node *head = new node;
head->number=1;
cin>>n;
create(head,n);
cin>>k;
node *p = head;
node *q = head;
int count = 1;
while (q->next!=head)
{
q=q->next;
}
while(p->next!=p){
if(count%k==0||count%10==k){
q->next = p->next;
// cout<<p->number<<endl;
delete p;
p = q->next;
}
else {
q = p;
p = p->next;
}
count++;
}
cout<<p->number<<endl;
system("pause");
return 0;
}