0% found this document useful (0 votes)
225 views25 pages

DAA E-Lab

The document provides code for calculating the maximum amount of water that can be contained within rectangular blocks placed in a given integer array, and includes functions to find the maximum value in nested left and right halves of the array. It also contains code for a main function that takes user input for the array size and values and calls the maximum water function to output the result.

Uploaded by

srinithi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
225 views25 pages

DAA E-Lab

The document provides code for calculating the maximum amount of water that can be contained within rectangular blocks placed in a given integer array, and includes functions to find the maximum value in nested left and right halves of the array. It also contains code for a main function that takes user input for the array size and values and calls the maximum water function to output the result.

Uploaded by

srinithi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

SESSI

ON1:
-
I
nthef
oll
owi
ngf
igur
e,y
oucanseear
ect
angul
ar:
-

#i
ncl
ude<bi
ts/
stdc++.
h>

usi
ngnamespacest
d;

v
oidsol
ve(
){

cout
<<"
ret
urn(
l-
2*x)
*(b-
2*x)
*x;
";

i
ntmai
n()

i
ntt
c;

doubl
ea,
b,c,
res,
l,w,
x;

scanf
("%d"
,&t
c);

whi
l
e(t
c--
){

scanf
("%l
f%l
f"
,&l
,&w)
;

a=12.
0;

b=-
4.0*(
l+w)
;

c=l
*w;

x=(
-b-sqr
t(b*
b-4.
0*a*
c))/(
2.0*
a);

r
es=(
l-2*
x)*(
w-2*
x)*x;

pr
int
f("
%.9f
\n"
,res)
;

r
etur
n0;
}

Mr
.somuhasanot
herpr
obl
em f
orAgi
today
.

#i
ncl
ude<bi
ts/
stdc++.
h>

usi
ngnamespacest
d;

i
ntmai
n()

i
ntt
;

ci
n>>t
;

whi
l
e(t
--
){

i
ntb,
n,
r;

ci
n>>b>>n>>r
;

i
ntz=1;

f
or(
inti
=1;
i
<=n;
i
++)
{

z=z
*i;

i
ntr
es;

r
es=pow(
b,z)
;

cout
<<r
es%r
<<endl
;

r
etur
n0;

cout
<<"
if
(n%2==1)
";

}
Maj
orKat
hir
avanhasachar
tofdi
sti
nct:
-

#i
ncl
ude<bi
ts/
stdc++.
h>

#def
inef
(n)f
or(
inti
=0;
i
<n;
i
++)

usi
ngnamespacest
d;

i
ntmai
n()

i
ntn;

ci
n>>n;

i
ntar
r[
n];

i
ntr
es=10000;

f
(n)
{

ci
n>>ar
r[
i]
;

f
(n)
{

f
or(
intj
=i+1;
j
<n;
j
++)
{

i
f(
arr
[i
]>ar
r[
j]
){

r
es=mi
n(r
es,
arr
[i
]-
arr
[j
])
;

}
cout
<<r
es;

r
etur
n0;

cout
<<"
whi
l
e";

Theal
l
iesar
etr
yingt
ogetamessage

#i
ncl
ude<bi
ts/
stdc++.
h>

usi
ngnamespacest
d;

v
oidsol
ve(
){ cout
<<"
break;
";}

i
ntmai
n()
{

st
ri
ngs1,
s2,
s3,
s4;

doubl
er;

doubl
eh;

ci
n>>s1>>r
>>s2>>s3>>s4;

i
f(
s2=="
FEET"
)

r
=r/
3.28;

/
/cout
<<r
<<endl
;

i
f(
s2=="
KILOMETERS"
)r=r
*1000;

i
f(
s2=="
YARDS"
)r=r
*0.
9144;

i
f(
s2=="
INCHES"
)r=r
*0.
0254;

i
f(
s2=="
MILES"
)r=r
*1609.
34;

i
f(
s4=="
HOUR"
)r=r
/3600;
i
f(
s4=="
MINUTE"
)r=r
/60;

i
f(
s2=="
CENTI
METERS"
)r=r
/100;

h=r
*r/
(2*
9.805)
;

cout
<<s1<<"wi
l
llauncht
hemessage"
<<f
ixed<<set
preci
si
on(
2)<<h<<"met
ershi
gh,
";

i
f(
h>50)cout
<<"
OUCH!
";

el
sei
f(
h<25)cout
<<"
SPLAT!
";

el
secout
<<"
SUCCESS!
";

r
etur
n0;
}

Gi
ven‘
m’posi
ti
vei
nteger
sdenot
inganupgr
adi
ngmap:
-

#i
ncl
ude<bi
ts/
stdc++.
h>

usi
ngnamespacest
d;

#def
inef
(n)f
or(
i=0;
i
<n;
i
++)

#def
ineg(
n)f
or(
i=1;
i<n;
i++)

#def
inek(
n)f
or(
i=n-
2;i
>=0;
i
--)

i
ntmaxWat
er(
intar
r[
],
intn)

i
ntl
eft
[n]
,
i;

i
ntr
ight
[n]
;

i
ntwat
er=0;

l
eft
[0]=ar
r[
0];

g(
n)
l
eft
[i
]=max(
lef
t[
i-1]
,ar
r[
i]
);

r
ight
[n-1]=ar
r[
n-1]
;

k(
n)

r
ight
[i
]=max(
ri
ght
[i+1]
,ar
r[
i]
);

f
or(
i=1;
i<n-
1;i
++)

i
ntv
ar=mi
n(l
eft
[i
-1]
,
right
[i
+1]
);

i
f(
var>ar
r[
i]
)

wat
er+=v
ar-ar
r[
i]
;

r
etur
nwat
er;

i
ntmai
n()

i
ntn,
i
;

ci
n>>n;

i
ntar
r[
n];

f
(n)
{

ci
n>>ar
r[
i]
;

cout<<maxWat
er(
arr
,n)
;

r
etur
n0;

TheMaskat
eabl
ockofdy
nami
tet
osav
e:-
#i
ncl
ude<bi
ts/
stdc++.
h>

usi
ngnamespacest
d;

i
ntmai
n()

f
loata,
c,
d;

st
ri
ngb;

ci
n>>a>>b>>c;

f
loatr
es;

i
ntz=b.
size(
);

i
f(
z==1)

d=b[
0]-
48;

el
se

d=(
fl
oat
)(b[
0]-
48)
/(b[
2]-
48)
;

r
es=a*
d*0.
45*
7.5;

i
f(
res>c)
{

cout
<<r
es<<"t
heMaskshoul
dnoteati
t!
";

el
se

cout
<<f
ixed<<set
preci
sion(
2)<<r
es<<"t
heMaskcaneati
t!
";

r
etur
n0;

cout
<<"
for
";

}
Ther
eisaGangar
ooi
nit
ial
l
ypl
acedatt
he:
-

#i
ncl
ude<st
dio.
h>

i
ntmai
n()
{

i
ntx,
y,
s,
t,
i
,j
,count
=0;

scanf
("%d"
,&x)
;

scanf
("%d"
,&y
);

scanf
("%d"
,&s)
;

scanf
("%d"
,&t
);

f
or(
i=x;
i
<=x+s;
i
++)
{

f
or(
j=y
;j
<=y
+s;
j
++)
{

i
f(
i+j
<=t
)

count
++;

pr
int
f("
%d"
,count
);

r
etur
n0;

pr
int
f("
if
(s>=t
)i
f(
s<=t
/2)
");

I
nspect
orGadgetj
usti
nst
all
ednewspr
ings:
-
#i
ncl
ude<bi
ts/
stdc++.
h>

usi
ngnamespacest
d;

i
ntmai
n()

st
ri
ngs1,
s2,
s3,
s4,
s5,
s6;

ci
n>>s1>>s2>>s3>>s4>>s5>>s6;

f
loata,
b,
c;

i
f(
s2=="
?")
{

b=st
of(
s4)
;

c=st
of(
s6)
;

/
/cout
<<c;

cout
<<"
F"<<f
ixed<<set
preci
sion(
2)<<(
-b)
*c;

el
sei
f(
s4=="
?")
{

a=st
of(
s2)
;

c=st
of(
s6)
;

cout
<<"
K"<<f
ixed<<set
preci
sion(
2)<<a/
(-c)
;

el
se

a=st
of(
s2)
;

b=st
of(
s4)
;
cout
<<"
X"<<f
ixed<<set
preci
sion(
2)<<a/
(-b)
;

r
etur
n0;

Adoubl
e-squar
enumberi
sani
ntegerYwhi
chcanbe:
-

#i
ncl
ude<bi
ts/
stdc++.
h>

usi
ngnamespacest
d;

i
ntsumSquar
e(i
ntn)

{
i
ntr
es=0;

f
or(
longi
=0;
i*i
<=n;
i++)

f
or(
longj
=i;
j*j
<=n;
j++)

i
f((
i*i
+j*j
==n)){

r
es++;

r
etur
nres;

i
ntmai
n()

i
ntt
;

ci
n>>t
;

i
nti
=1;

whi
l
e(t
--
){

i
ntn;

ci
n>>n;

cout
<<"
Line#"
<<i
<<"
:"<<sumSquar
e(n)
<<endl
;

i
++;

r
etur
n0;

cout
<<"
for
(i
=0;
i
<=sqr
t(y
);i
++)f
or(
j=0;
j
<=i
;
j++)
";

Gi
vent
woi
nteger
s:‘
b’and‘
a’
#i
ncl
ude<i
ost
ream>

usi
ngnamespacest
d;

i
ntmai
n()

i
ntt
;

l
ongl
ongm;

l
ongl
ongn;

l
ongl
ongans;

scanf
("%d"
,&t
);

f
or(
intcs=1;
cs<=t
;cs++){

scanf
("%l
l
d%l
l
d",
&n,
&m)
;

ans=(
n*m )/2;

pr
int
f("
%ll
d\n"
,ans)
;

SESSI
ON2:
-
Gr
eatnews!Yougett
ogot
oJapan:
-
#i
ncl
ude<i
ost
ream>

usi
ngnamespacest
d;

i
ntmai
n()

i
nti
tems;

i
nta,
j
,cnt
=0;

ci
n>>a>>i
tems;

i
ntc[
it
ems]
;

st
ri
ngs[
it
ems]
;

f
or(
j=0;
j
<it
ems;
j
++)
{

ci
n>>s[
j]
>>c[
j]
;

i
f(
c[j
]<a)
{

cout
<<"
Icanaf
for
d"<<s[
j]
<<endl
;

a=a-
c[j
];

el
se{

cnt
++;

cout
<<"
Ican'
taf
for
d"<<s[
j]
<<endl
;

/
/cout
<<cnt
;

i
f(
cnt
==i
tems)
cout
<<"
Ineedmor
eYen!
";

el
se

cout
<<a;

r
etur
n0;

cout
<<"
for
(i
=1;
i
<=y
en;
i
++)i
nti
,
j;
";

Scr
oogeMcduck’
svaul
tispr
act
ical
l
y:-

#i
ncl
ude<i
ost
ream>

usi
ngnamespacest
d;

i
ntmai
n()

i
ntp,
q,
r,
i
;

i
ntc;

ci
n>>c;

f
or(
i=0;
i
<c;
i
++)
{

ci
n>>p>>q>>r
;

q=q+(
r-
1)/
5;

r
=(r
-1)
%5+1;

p=p+(
q-1)
/10;

q=(
q-1)
%10+1;

cout
<<p<<""
;
cout
<<q<<""
;

cout
<<r
<<endl
;

r
etur
n0;

Ti
naownsamat
chmaki
ngcompany
,whi
chev
ent
oher:
-

#i
ncl
ude<bi
ts/
stdc++.
h>

usi
ngnamespacest
d;

i
ntmai
n()

i
ntt
,n;

ci
n>>t
;

whi
l
e(t
--
){

ci
n>>n;

i
nta[
n],
b[n]
,
sum=0;

f
or(
inti
=0;
i
<n;
i
++)

ci
n>>a[
i]
;

f
or(
inti
=0;
i
<n;
i
++)

ci
n>>b[
i]
;

sor
t(a,
a+n)
;

sor
t(b,
b+n)
;
f
or(
inti
=0;
i
<n;
i
++)
{

i
f(
a[i
]%b[
n-i
-1]
==0|
|b[
n-i
-1]
%a[
i]
==0)

sum++;

cout
<<sum<<endl
;

r
etur
n0;

Acev
ent
ura,
petdet
ect
ive,
isont
hehuntf
orar
are:
-

#i
ncl
ude<bi
ts/
stdc++.
h>

usi
ngnamespacest
d;

#def
inep1cout
<<"
Ace,
mov
efast
,pi
geoni
sat(
"<<i
<<"
,0)
";

#def
inep2cout
<<"
Ace,
mov
efast
,pi
geoni
sat(
"<<(
i-
i/
z)%z<<"
,"
<<i
/z<<"
)"
;

#def
inep3cout
<<"
Nopi
geon,
tryanot
hermap,
Ace"
;

#def
ineacont
inue;

#def
inef
(n)f
or(
inti
=0;
i
<z;
i
++)

#def
inewhi
l
e1whi
l
e((
scanf
("%c"
,&s[
i]
))!
=EOF)

i
ntmai
n()
{

st
ri
ngs1;
cin>>s1;

i
ntz=s1.
siz
e()
;

f
(n)
{
i
f(
s1[
i]
=='
P'
){p1

r
etur
n0;
}

/
/cout
<<z<<endl
;

i
nti
=0,
cnt
=0;

chars[
10000]
;

whi
l
e1{

i
f(
s[i
]=='
P'
){

cnt
=1;

br
eak;

i
++;

i
f(
cnt
==1)p2

el
sep3}

Thesapphi
reconsul
ti
ngandmar
ket
ingcompanyi
saddi
ng:
-

#i
ncl
ude<st
dio.
h>

#i
ncl
ude<st
dli
b.h>

i
nti
sqr
t(n)i
ntn;
{

i
nti
;
f
or(
i=0;
i
*i<n;
i
++)
;

r
etur
ni;

i
ntmai
n(){

i
ntc;

i
ntt
,h,
s,
i,
j
;

i
ntd;

scanf
("%d"
,&c)
;

f
or(
i=0;
i
<c;
i
++){

s=0;

scanf
("%d%d"
,&t
,&h)
;

d=i
sqr
t(t
);

s+=t
+(d*
4);

f
or(
j=1;
j
<h;
j
++){

s+=3;

s+=(
d+j
)*4;

i
f(
(d+j
)>2)

s+=(
d+j
-2)
*2;

pr
int
f("
%dl
i
ter
s\n"
,s)
;

r
etur
n0;

}
Ganesanhasast
ri
ngSconsi
sti
ngofl
ower
case:
-

#i
ncl
ude<bi
ts/
stdc++.
h>

usi
ngnamespacest
d;

i
ntmai
n()

st
ri
ngs,
s2;

ci
n>>s>>s2;

i
ntz=s.
lengt
h()
;

i
nti
;

i
nta[
z];

f
or(
i=0;
i
<(i
nt)
s.l
engt
h()
;i
++)
{

a[
i]
=s[
i+1]
-s[
i]
;

f
or(
inti
=0;
i
<z-
2;i
++)
{

i
f(
a[i
]!
=a[
i+1]
){

cout
<<"
No"
;

r
etur
n0;
}

cout
<<"
Yes"
;

r
etur
n0;
}

RSAi
sapubl
i
ckeycr
ypt
osy
stem.

#i
ncl
ude<bi
ts/
stdc++.
h>

usi
ngnamespacest
d;

v
oidsol
ve(
){

cout
<<"
break;
";

bool
isPr
oduct
(i
ntnum)

i
ntcnt=0;

f
or(
inti
=2;
cnt<2&&i
*i<=num;
++i
){

whi
l
e(num %i
==0){

num /
=i;

++cnt
;

i
f(num >1)

++cnt
;

r
etur
ncnt==2;

}
v
oidf
indNumber
s(i
ntN)

v
ect
or<i
nt>v
ec;

f
or(
inti
=1;
i<=N;
i++){

i
f(i
sPr
oduct
(i
)){

v
ec.
push_
back(
i)
;

cout
<<v
ec.
size(
)<<endl
;

i
ntmai
n()

i
ntt
,N;

ci
n>>t
;

whi
l
e(t
--
){

ci
n>>N;

f
indNumber
s(N)
;

r
etur
n0;

ROYGBI
Visn’
tjustanacr
ony
m,i
t’
sawayofl
i
fe:
-
#i
ncl
ude<bi
ts/
stdc++.
h>

usi
ngnamespacest
d;

v
oidsol
ve(
){

cout
<<"
forbr
eak;
";

i
ntmai
n()

i
ntt
=4;

whi
l
e(t
--
){

st
ri
ngs1,
s2;

ci
n>>s1>>s2;

i
f(
s2=="
WHI
TE"
)

cout
<<"
LIGHT"
<<s1<<endl
;

el
sei
f(
s2=="
BLACK"
)

cout
<<"
DARK"
<<s1<<endl
;

el
sei
f(
s1=="
WHI
TE"
)

cout
<<"
LIGHT"
<<s2<<endl
;

el
sei
f(
s1=="
BLACK"
)

cout
<<"
DARK"
<<s2<<endl
;

el
sei
f(
(s1=="
RED"
&&s2=="
YELLOW"
)|
|(
s1=="
YELLOW"
&&s2=="
RED"
))

cout
<<"
ORANGE"
<<endl
;

el
sei
f(
(s1=="
BLUE"
&&s2=="
YELLOW"
)|
|(
s1=="
YELLOW"
&&s2=="
BLUE"
))

cout
<<"
GREEN"
<<endl
;

el
sei
f(
(s1=="
BLUE"
&&s2=="
RED"
)|
|(
s1=="
RED"
&&s2=="
BLUE"
))

cout
<<"
PURPLE"
<<endl
;

el
sei
f(
s1==s2)

cout
<<s1<<endl
;

el
se

cout
<<"
N/A"
<<endl
;

r
etur
n0;

}
Thepeopl
eofv
adi
pat
tihav
edeci
dedt
opai
nteachoft
hei
rvi
l
las:
-

#i
ncl
ude<bi
ts/
stdc++.
h>

usi
ngnamespacest
d;

#def
inef
ainoui
os_
base:
:
sync_
wit
h_st
dio(
fal
se)
;ci
n.t
ie(
NULL)

#def
inel
ll
ongl
ong

#def
inemod1000000007

v
oidsol
ve(
){

cout
<<"
for
(i
=0;
i
<tc;
i
++)f
or(
j=0;
j
<N;
j
++)
for
(j
=1;
j
<N;
j
++)
";

i
ntmai
n()
{

f
ainou;

l
lt;

ci
n>>t
;

i
nti
=1;

whi
l
e(t
--
){

l
ln;

ci
n>>n;
l
la[
n][
3],
ans;

ci
n>>a[
0][
0]>>a[
0][
1]>>a[
0][
2];

f
or(
lli
=1;
i
<n;
i
++)
{

ci
n>>a[
i]
[0]
>>a[
i]
[1]
>>a[
i]
[2]
;

a[
i]
[0]
+=mi
n(a[
i-
1][
1],
a[i
-1]
[2]
);

a[
i]
[1]
+=mi
n(a[
i-
1][
0],
a[i
-1]
[2]
);

a[
i]
[2]
+=mi
n(a[
i-
1][
0],
a[i
-1]
[1]
);

ans=mi
n(a[
n-1]
[0]
,
a[n-
1][
1])
;

ans=mi
n(a[
n-1]
[2]
,
ans)
;

cout
<<"
Line"
<<i
++<<"
:"<<ans<<"
\n"
;

Shankari
sav
oll
eybal
ltr
aineratgov
ernmentschool
inmadur
ai:
-

#i
ncl
ude<bi
ts/
stdc++.
h>

usi
ngnamespacest
d;

t
ypedefl
ongl
ongLL;

consti
ntN=(
int
)1e6+6,
mod=(
int
)0;

i
nta[
N];

l
ongl
ongsum[
N];

i
ntmai
n(){

i
ntt
c;
ci
n>>t
c;

f
or(
intt
t=1;
tt<=t
c;++t
t){

i
ntn,
p;

ci
n>>n>>p;

f
or(
intj
=0;
j<n;
++j
)

ci
n>>a[
j]
;

sor
t(a,
a+n)
;

i
nti
;

f
or(
i=0;
i
<n;
i
++)

sum[
i+1]=sum[
i]+a[
i]
;

l
ongl
ongr
es=1e18;

f
or(
intj
=p-1;
j<n;
++j
){

l
ongl
ongs=sum[
j+1]-sum[
j-(
p-1)
];

l
ongl
ongcost=(
LL)a[
j]*p-s;

r
es=mi
n(r
es,
cost
);

cout<<r
es<<'
\n'
;

You might also like