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
/
E_Prakhar.c
119 lines (115 loc) · 2.99 KB
/
E_Prakhar.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include<stdio.h>
#include<stdlib.h>
#define node struct node
node{
int val;
node* forward;
node* backward;
};
int main(){
char ch;
node* head;
node* tail;
node* prev = (node*)malloc(sizeof(node));
scanf("%c" , &ch);
int i = 0;
while(ch != '\n'){
node* temp = (node*)malloc(sizeof(node));
temp -> val = ch - '0';
if(i){
temp -> backward = prev;
prev -> forward = temp;
prev = temp;
}else{
temp -> backward = NULL;
prev = temp;
head = temp;
}
scanf("%c" , &ch);
i++;
}
prev -> forward = NULL;
tail = prev;
int n,x;
scanf("%d%*c", &n);
node* temp;
while (n--)
{
char command;
scanf("%c", &command);
switch (command)
{
case 'L':
scanf("%c%*c", &command);
if (command == 'S')
{
temp = head;
while(temp -> forward != NULL){
temp -> val = (temp -> forward) -> val;
temp = temp -> forward;
}
temp -> val = 0;
}
else
{
temp = head;
int cpy = temp -> val;
while(temp -> forward != NULL){
temp -> val = (temp -> forward) -> val;
temp = temp -> forward;
}
temp -> val = cpy;
}
break;
case 'R':
scanf("%c%*c", &command);
if (command == 'S')
{
temp = tail;
while(temp -> backward != NULL){
temp -> val = (temp ->backward) -> val;
temp = temp -> backward;
}
temp -> val = 0;
}
else
{
temp = tail;
int cpy = temp -> val;
while(temp -> backward != NULL){
temp -> val = (temp ->backward) -> val;
temp = temp -> backward;
}
temp -> val = cpy;
}
break;
case 'I':
scanf("%*c%*c%*c");
temp = tail;
x = 1;
while(temp != NULL){
int sum = (temp -> val) + x;
temp -> val = sum % 2;
x = sum / 2;
temp = temp -> backward;
}
break;
case 'D':
scanf("%*c%*c%*c");
temp = tail;
x = 0;
while(temp != NULL){
int sum = (temp -> val) + x + 1;
temp -> val = sum % 2;
x = sum / 2;
temp = temp -> backward;
}
break;
}
}
while(head != NULL){
printf("%d" , head -> val);
head = head -> forward;
}
return 0;
}