This repository has been archived by the owner on Jun 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
G_Eva.c
60 lines (58 loc) · 1.36 KB
/
G_Eva.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include <stdlib.h>
struct node{
int data;
struct node* next;
struct node* prev;
};
int main()
{
int n, m, temp;
scanf("%d %d",&n,&m);
int a[m];
struct node* head=NULL;
struct node* tail=NULL;
for(int i=0;i<n;i++){
scanf("%d", &temp);
struct node* p=(struct node*)malloc(sizeof(struct node));
p->data=temp;
if(tail!=NULL)tail->next=p;
p->prev=tail;
tail=p;
p->next=NULL;
if(i==0) head=p;
}
for(int i=0;i<m;i++){
scanf("%d", &a[i]);
}
struct node* cur=head;
struct node* swap, *h, *t;
for(int i=0;i<m;i++){
for(int j=0;j<a[i];j++){
if(j==0) h=cur;
if(j==a[i]-1) t=cur;
//changing the links
swap=cur->prev;
cur->prev=cur->next;
cur->next=swap;
//changing value of data
cur->data*=a[i];
//then changing the value of cur
cur=cur->prev;
}
swap=h->next;
h->next=t->prev;
t->prev=swap;
if(h->next!=NULL) h->next->prev=h;
if(t->prev!=NULL) t->prev->next=t;
if(i==0) head=t;
}
cur=head;
//printf("%d\n",cur->data);
while(cur!=NULL){
printf("%d",cur->data);
if(cur->next!=NULL) printf(" ");
cur=cur->next;
}
return 0;
}