久违的链表 mua mua mua !!!
#include<bits/stdc++.h>
using namespace std;
struct node{
int data; // 单链表的数据域
struct node *Next; // 单链表的指针域
};
/**
建立1:头插,逆序
*/
node *creat1(int n){
node *head;
head=(node*)malloc(sizeof(node));
head->Next=NULL;
for(int i=1;i<=n;i++){
node *p;
p=(node *)malloc(sizeof(node));
int x;
cin>>x;
p->data=x;
p->Next=head->Next;
head->Next=p;
}
return head;
}
/**
建立2:尾插 ,顺序
*/
node *creat2(int n){
node *head;
head=(node *)malloc(sizeof(node));
head->Next=NULL;
node *q;
q=head;
for(int i=1;i<=n;i++){
node *p;
p=(node *)malloc(sizeof(node));
int x;
cin>>x;
p->data=x;
q->Next=p;
q=p;
}
q->Next=NULL;
return head;
}
/**
插入 位置:pos 插入val
*/
node *add(node *head,int pos,int val,int n){
node *pre;
pre=head;
for(int i=1;i<pos;i++){
pre=pre->Next;
}
node *p;
p=(node *)malloc(sizeof(node));
p->data=val;
p->Next=pre->Next;
pre->Next=p;
return head;
}
/**
删除 值为val的元素
*/
node *Delete_val(node *head,int val){
node *p,*pre;
p=head->Next;
pre=head;
while(p->data!=val){
pre=p;
p=p->Next;
}
pre->Next=p->Next;
free(p);
return head;
}
void print(node *p){
p=p->Next;
if(p) cout<<p->data;
p=p->Next;
while(p){
cout<<" "<<p->data;
p=p->Next;
}
cout<<endl;
}
/**
删除 位置 pos
*/
node *Delete_pos(node *head,int pos){
node *p,*pre;
p=head->Next;
pre=head;
int i=1;
while(i<pos){
i++;
pre=p;
p=p->Next;
}
pre->Next=p->Next;
free(p);
return head;
}
int main (){
int n;
cin>>n;
/**
node *head ;
head=creat1(n);
print(head);
*/
node *head;
head =creat2(n);
//print(head);
int m;
cin>>m;
for(int i=0;i<m;i++){
/*int x,val;
cin>>x>>val;
x++;
head=add(head,x,val,n);*/
char ch[3];
scanf("%s",ch);
if(ch[0]=='D'){
int st,ed;
cin>>st>>ed;
int k=ed-st+1;
while(k--){
head=Delete_pos(head,st);
}
}
else if(ch[0]=='I'){
int st,sum;
cin>>st>>sum;
while(sum--){
int val;
cin>>val;
head=add(head,++st,val,n);
}
}
/**int st,ed;
cin>>st>>ed;
int k=ed-st+1;
while(k--){
head=Delete_pos(head,st);
}*/
/*char ch[3];
scanf("%s",ch);
if(ch[0]=='D'){
int pos;
cin>>pos;
head=Delete_pos(head,pos);
}
else if(ch[0]=='I'){
int a,b;
cin>>a>>b;
head=add(head,a+1,b,n);
}*/
/**
int pos;
cin>>pos;
head=Delete_pos(head,pos);*/
}
print(head);
return 0;
}
/**
双向链表建立:尾插 顺序
*/
node *creat2(int n){
node *head;
head=(node *)malloc(sizeof(node));
head->Next=NULL;
head->pre=NULL;
node *q;
q=head;
for(int i=1;i<=n;i++){
node *p;
p=(node *)malloc(sizeof(node));
int x;
cin>>x;
p->data=x;
p->Next=NULL;
p->pre=q;
q->Next=p;
q=p;
}
q->Next=NULL;
return head;
}
#include<bits/stdc++.h>
using namespace std;
struct node{
int data; // 单链表的数据域
struct node *Next; // 单链表的指针域
};
/**
循环链表建立:尾插 顺序
*/
node *creat2(int n){
node *head;
head=(node *)malloc(sizeof(node));
head->data=1;
head->Next=NULL;
node *q;
q=head;
for(int i=2;i<=n;i++){
node *p;
p=(node *)malloc(sizeof(node));
p->data=i;
p->Next=NULL;
q->Next=p;
q=p;
}
q->Next=head;
return head;
}
int Count(node *head ,int n){
node *p,*q;
q=head;
while(q->Next!=head) q=q->Next;
for(int i=1;;i++){
p=q->Next;
if(i%5==0){
if(p->data==1) return i/5;
q->Next=p->Next;
}
else q=p;
}
}
int main (){
int n;
while(cin>>n){
if(n==0) break;
node *head;
head =creat2(n);
cout<<Count(head,n)<<endl;
}
return 0;
}