Your friend is a chief architect, who is working on building a skyscraper, in Mumbai. Theconstructionisinsuchawaythatthefloorswillbeconstructedinotherfactories andtheywillbeassembled.Allthesizeswillbe
Question:
Your friend is a chief architect, who is working on building a skyscraper, in Mumbai. Theconstructionisinsuchawaythatthefloorswillbeconstructedinotherfactories andtheywillbeassembled.Allthesizeswillbedistinct.
TheskyscraperneedstobeconstructedinNdayswiththefollowingconditions:
- Everydayafloorisconstructedinaseparate factoryofdistinctsize.
- Thefloorwiththelargersizemustbeplacedatthebottomofthebuilding.
- Thefloorwiththesmaller sizemustbeplacedatthetopofthebuilding.
Note:Afloorcannotbeassembledinthebuildinguntilallfloors largerinsizeareplaced.
Asafriendhewantsyoutobuildasmallprogramthatwillhelphimanalyze theconstructionprocess, toavoidmanual workanderrors.
Input
FirstLine:containsthetotalfloorsNinthebuilding
SecondLineonwards:ContainsNinputsinwhichtheithinteger denotesthesizeofthefloorthatwillbegiventoarchitectbyfactoriesontheithday.
Output
Youarerequired toprintNlines.Printthesizeofthefloorindescendingorder,whichcanbeassembled.
Ifnofloorcanbeassembled ontheithday,leavethelineempty.SampleTestCases
TestCase1
enterthetotalnooffloorsinthebuilding3
enterthefloorsizegivenonday:13
enterthefloorsizegivenonday:21
enterthefloorsizegivenonday:32
Theorder ofconstructionisasfollows
Day:1
3
Day:2
Day:3
21
Explanation
Thelargest floorsizeisavailableonday1itself,henceitwillbeassembled onday1.
Ontheseconddayfloorofsize1isavailable andcannotbeassembledasthefloorofsize2isnotavailable.
Onthethirddayfloorofsize2,isavailable andaccordingly,theremainingfloor(2,1)willassembleintheorder2,1
--------------------------------------------------------------------------------------------------------------------------
TestCase2
enterthetotalnooffloorsinthebuilding5
enterthefloorsizegivenonday:1
4
enterthefloorsizegivenonday:2
5
enterthefloorsizegivenonday:3
1
enterthefloorsizegivenonday:4
2
enterthefloorsizegivenonday:5
3
Theorder ofconstructionisasfollows
Day:1
Day:2
54
Day:3
Day:4
Day:5
321
Explanation
Onthefirstday,thefloorofsize4isgiven.Butitcannotbeassembled asthefloorofsize5isstillremaining.
Onthesecondday,thefloorofsize5isgivensonowthefloorofsizes5and4canbeassembled
Onthethirdandfourthdays,floorscannotbeassembled asthesizeof3needstobegivenyet.Therefore,theselinesareempty.
Onthefifthday,allthefloorsofsizes3,2,and1canbeplaced.
--------------------------------------------------------------------------------------------------------------------------
TestCase3
enterthetotalnooffloorsinthebuilding10
enterthefloorsizegivenonday:1
1
enterthefloorsizegivenonday:2
2
enterthefloorsizegivenonday:3
3
enterthefloorsizegivenonday:4
8
enterthefloorsizegivenonday:5
9
enterthefloorsizegivenonday:6
10
enterthefloorsizegivenonday:7
4
enterthefloorsizegivenonday:8
5
enterthefloorsizegivenonday:9
7
enterthefloorsizegivenonday:10
6
Theorderofconstructionisasfollows
Day:1
Day:2
Day:3
Day:4
Day:5
Day:6
1098
Day:7
Day:8
Day:9
7
Day:10
654321
Instructions:
- Youcanuseanyinbuiltjavafunction/stoimplementtheabovefunctionalities
- YoucanchooseanyDataStructure(Stack,Queue,LinkedList)toimplementtheabovefunctionality.
Advanced Financial Accounting
ISBN: 978-0132928939
7th edition
Authors: Thomas H. Beechy, V. Umashanker Trivedi, Kenneth E. MacAulay