-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChef and Sub Array_CDLL.cpp
127 lines (102 loc) · 2.28 KB
/
Chef and Sub Array_CDLL.cpp
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
120
121
122
123
124
125
126
127
#include<iostream>
#include<math.h>
#include<malloc.h>
#include<stdio.h>
using namespace std;
typedef struct bin
{
struct bin *prev;
int data;
struct bin *next;
}bin;
void display(bin *head)
{
bin *tail,*current;
tail=current;
current=head;
int i=0;
printf("List Contains(sequence head to tail):\n");
do
{
printf("Node %d, Value: %d\n",i+1,current->data);
i++;
current=current->next;
} while(current!=head);
}
int main()
{
int n,k,p;
int i,j,count_one,l,max_count,lm_f_bit,m;
cin>>n>>k>>p;
char req[p];
bin *head,*temp,*current,*tail;
head=NULL;
tail=NULL;
temp=NULL;
current=NULL;
for(i=0;i<n;i++)
{
temp=(bin*)malloc(sizeof(bin));
if(temp!=NULL)
{
cin>>temp->data;
if(head==NULL)
{
current=temp;
head=temp;
head->next=head;
head->prev=head;
}
else
{
current->next=temp;
temp->prev=current;
temp->next=head;
head->prev=temp;
current=temp;
}
}
else
return -1;
}
cin>>req;
for(i=0;i<p;i++)
{
if(req[i]=='?')
{
count_one=max_count=0;
current=head;
temp=head;
for(l=0;l<k;l++)
{
if(current->data==1)
count_one++;
current=current->next;
}
lm_f_bit=temp->data;
temp=temp->next;
max_count=count_one;
while(current!=head)
{
if(current->data==1 && lm_f_bit==0)
count_one++;
if(current->data==0 && lm_f_bit==1)
count_one--;
current=current->next;
lm_f_bit=temp->data;
temp=temp->next;
if(count_one>max_count)
max_count=count_one;
if(max_count==k)
break;
}
cout<<max_count<<"\n";
}
else
{
temp=head->prev;
head=temp;
}
}
return 0;
}