标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 11527 | Accepted: 5293 |
Description
Input
Output
Sample Input
5 Xiaoming Xiaohua Xiaowang Zhangsan Lisi 2,3
Sample Output
Zhangsan Xiaohua Xiaoming Xiaowang Lisi
Source
1 #include <cstdio> 2 #include <cstring> 3 #include <string> 4 #include <queue> 5 #include <stack> 6 #include <iostream> 7 using namespace std; 8 struct node{ 9 string name; 10 node *next; 11 }; 12 int main(){ 13 //freopen("D:\\INPUT.txt","r",stdin); 14 int n; 15 scanf("%d",&n);//用例只有一组,写成while(scanf("%d",&n)),会超时 16 int i,j; 17 node *p,*head,*tail; 18 head=tail=new node(); 19 cin>>(head->name); 20 head->next=head; 21 for(i=1;i<n;i++){ 22 p=new node(); 23 cin>>p->name; 24 p->next=head;//循环链表 25 tail->next=p; 26 tail=p; 27 } 28 int w,s; 29 scanf("%d,%d",&w,&s); 30 w--; 31 while(n>1){ 32 w=(w+s-1)%n;//下一个编号 33 node *q=tail; 34 p=head; 35 for(i=1;i<=w;i++){ 36 q=p; 37 p=p->next; 38 } 39 cout<<p->name<<endl; 40 q->next=p->next; 41 delete p; 42 if(!w){ 43 head=q->next; 44 } 45 else{ 46 if(w==n-1){ 47 tail=q; 48 } 49 } 50 n--; 51 } 52 cout<<head->name<<endl; 53 delete head; 54 return 0; 55 }
标签:
原文地址:http://www.cnblogs.com/Deribs4/p/4644460.html