-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask0b.cpp
More file actions
111 lines (102 loc) · 2.59 KB
/
Copy pathtask0b.cpp
File metadata and controls
111 lines (102 loc) · 2.59 KB
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
#include<iostream>
#include<conio.h>
using namespace std;
int curtain[1000],s[1000],k[1000],j[1000], query, noc, noq;
void print(int a[1000])
{
int i;
for(i=0;i<noc;i++)
cout<<a[i]<<" ";
cout<<"\n";
}
void cpy(int a[1000])
{
int i;
for(i=0;i<noc;i++)
{
a[i]=curtain[i];
}
}
void sobha(int q)
{
int i=noc-1;
for(i=noc-1; i>=0; i--)
{
if(s[i]>=q)
{
s[i]=s[i]-q;
break;
}
}
if(i==-1)
{
cout<<"Not available\n";
return;
}
print(s);
}
void kamal(int q)
{
int i,min,j;
min = abs(q-k[noc-1]);
j=noc-1;
for(i=noc-2;i>=0;i--)
{
if((min>abs(q-k[i]))&&(k[i]>=q))
{
min = abs(q-k[i]);
j=i;
}
if(k[j]<q)
{
cout<<"Not available\n";
return;
} }
k[j] = k[j]- q;
print(k);
}
void jasmine(int q)
{
int i, max = j[noc-1], l = noc-1;
for(i=noc-2;i>=0;i--)
{
if((max<j[i])&&(j[i]>=q))
{
max = j[i];
l=i;
}
}
if(j[l]<q)
{
cout<<"Not available\n";
return;
}
j[l] = j[l]-q;
print(j);
}
int main()
{
int i, query;
cout<<"Enter number of curtains ";
cin>>noc;
cout<<"Enter the stack from bottom to top\n";
for(i=0;i<noc;i++)
cin>>curtain[i];
cpy(s);
cpy(k);
cpy(j);
cout<<"Enter number of queries ";
cin>>noq;
cout<<"Enter query\n";
for(i=0;i<noq;i++)
{
cin>>query;
sobha(query);
cout<<"\n";
kamal(query);
cout<<"\n";
jasmine(query);
cout<<"\n";
}
getch();
}