卡片游戏
时间限制(普通/Java) :
2000 MS/ 6000 MS 运行内存限制 : 65536 KByte
总提交 : 1372 测试通过 : 268
总提交 : 1372 测试通过 : 268
#include<iostream>
using namespace std;
struct link_node{
long i;
link_node* next;
};
int main(){
long n,i;
link_node *head,*tail,*p;
cin>>n;
if(n==1){
cout<<1<<endl;
return 0;
}
if(n==2){
cout<<1<<" "<<2<<endl;
return 0;
}
head = new link_node();
head->i = 1;
tail = head;
for(i=2;i<=n;++i){
p = new link_node();
p->i = i;
tail->next = p;
tail = p;
}
while(head->next!=tail){
cout<<head->i<<" ";
p = head;
head = head->next;
delete p;
p = head;
head = head->next;
tail->next = p;
tail = p;
}
cout<<head->i<<" "<<tail->i<<endl;
}