版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
實驗二棧和隊列的基本操作實現(xiàn)及其應用一、實驗目的1、熟練掌握棧和隊列的基本操作在兩種存儲結構上的實現(xiàn)。2、會用棧和隊列解決簡單的實際問題。二、實驗內容(可任選或全做)題目一、試寫一個算法,判斷依次讀入的一個以@為結束符的字符序列,是否為回文。所謂“回文“是指正向讀和反向讀都一樣的一字符串,如“321123”或“ableelba”相關常量及結構定義:#defineSTACK_INIT_SIZE100#defineSTACKINCREMENT10#defineOK1#defineERROR0typedefintSElemType;//棧類型定義typedefstructSqStack {SElemType*base;SElemType*top;intstacksize;}SqStack;設計相關函數(shù)聲明:判斷函數(shù):intIsReverse()棧:intInitStack(SqStack&S)intPush(SqStack&S,SElemTypee)intPop(SqStack&S,SElemType&e)intStackEmpty(s)題目二、編程模擬隊列的管理,主要包括:出隊列、入隊、統(tǒng)計隊列的長度、查找隊列某個元素e、及輸出隊列中元素。[實現(xiàn)提示]:參考教材循環(huán)隊列的有關算法,其中后兩個算法參考順序表的實現(xiàn)。題目三、RailsDescriptionThereisafamousrailwaystationinPopPush
ThelocaltraditionisthateverytrainarrivingfromthedirectionAcontinuesinthedirectionBwithcoachesreorganizedinsomeway.AssumethatthetrainarrivingfromthedirectionAhasN<=1000coachesnumberedinincreasingorder1,2,...,N.ThechieffortrainreorganizationsmustknowwhetheritispossibletomarshalcoachescontinuinginthedirectionBsothattheirorderwillbea1,a2,...,aN.Helphimandwriteaprogramthatdecideswhetheritispossibletogettherequiredorderofcoaches.YoucanassumethatsinglecoachescanbedisconnectedfromthetrainbeforetheyenterthestationandthattheycanmovethemselvesuntiltheyareonthetrackinthedirectionB.Youcanalsosupposethatatanytimetherecanbelocatedasmanycoachesasnecessaryinthestation.ButonceacoachhasenteredthestationitcannotreturntothetrackinthedirectionAandalsoonceithasleftthestationinthedirectionBitcannotreturnbacktothestation.InputTheinputconsistsofblocksoflines.Eachblockexceptthelastdescribesonetrainandpossiblymorerequirementsforitsreorganization.InthefirstlineoftheblockthereistheintegerNdescribedabove.Ineachofthenextlinesoftheblockthereisapermutationof1,2,...,N.Thelastlineoftheblockcontainsjust0.
Thelastblockconsistsofjustonelinecontaining0.OutputTheoutputcontainsthelinescorrespondingtothelineswithpermutationsintheinput.AlineoftheoutputcontainsYesifitispossibletomarshalthecoachesintheorderrequiredonthecorrespondinglineoftheinput.OtherwiseitcontainsNo.Inaddition,thereisoneemptylineafterthelinescorrespondingtooneblockoftheinput.Thereisnolineintheoutputcorrespondingtothelast``null''blockoftheinput.SampleInput512345541230665432100SampleOutputYesNoYes題目四、SlidingWindowDescriptionAnarrayofsizen≤106isgiventoyou.Thereisaslidingwindowofsizekwhichismovingfromtheveryleftofthearraytotheveryright.Youcanonlyseetheknumbersinthewindow.Eachtimetheslidingwindowmovesrightwardsbyoneposition.Followingisanexample:
Thearrayis[1
3
-1
-3
5
3
6
7],andkis3.WindowpositionMinimumvalueMaximumvalue[1
3
-1]
-3
5
3
6
7
-13
1
[3
-1
-3]
5
3
6
7
-33
1
3
[-1
-3
5]
3
6
7
-35
1
3
-1
[-3
5
3]
6
7
-35
1
3
-1
-3
[5
3
6]
7
36
1
3
-1
-3
5
[3
6
7]37Yourtaskistodeterminethemaximumandminimumvaluesintheslidingwindowateachposition.InputTheinputconsistsoftwolines.Thefirstlinecontainstwointegersnandkwhicharethelengthsofthearrayandtheslidingwindow.Therearenintegersinthesecondline.OutputTherearetwolinesintheoutput.Thefirstlinegivestheminimumvaluesinthewindowateachposition,fromlefttoright,respectively.Thesecondlinegivesthemaximumvalues.SampleInput8313-1-35367SampleOutput-1-3-3-333335567題目五(選作考查串知識)DNAEvolution【Description】Evolutionisaseeminglyrandomprocesswhichworksinawaywhichresemblescertainapproachesweusetogetapproximatesolutionstohardcombinatorialproblems.Youarenowtodosomethingcompletelydifferent.GivenaDNAstringSfromthealphabet{A,C,G,T},findtheminimalnumberofcopyoperationsneededtocreateanotherstringT.Youmayreversethestringsyoucopy,andcopybothfromSandthepiecesofyourpartialT.Youmayputthesepiecestogetheratanytime.YoumayonlycopycontiguouspartsofyourpartialT,andallcopiedstringsmustbeusedinyourfinalT.Example:FromS=“ACTG”createT=“GTACTAATAAT”GetGT.........bycopyingandreversing"TG"fromS.GetGTAC...bycopying"AC"fromS.GetGTACTA…..bycopying"TA"fromthepartialT.GetGTACTAATbycopyingandreversing"TA"fromthepartialT.GetGTACTAATAATbycopying"AAT"fromthepartialT.【Input】Thefirstlineofinputgivesasingleinteger,1≤k≤10,thenumberoftestcases.Thenfollow,foreachtestcase,alinewiththestringS,lengthofSislessthen19,andalinewiththestringT,lengthofTislessthen19.【Output】OutputforeachtestcasethenumberofcopyoperationsneededtocreateTfromS,or"impossible"ifitcannotbedone.【SampleInput】4ACGTTGCAACACGTTCGATCGAAAAAAAAAAAAAAAAAAAA【Sampleoutput】1impossible46題目六(選作考查數(shù)組知識)MagicSquares描述Followingthesuccessofthemagiccube,Mr.Rubikinventeditsplanarversion,calledmagicsquares.Thisisasheetcomposedof8equal-sizedsquares:12348765Inthistaskweconsidertheversionwhereeachsquarehasadifferentcolor.Colorsaredenotedbythefirst8positiveintegers.Asheetconfigurationisgivenbythesequenceofcolorsobtainedbyreadingthecolorsofthesquaresstartingattheupperleftcornerandgoinginclockwisedirection.Forinstance,theconfigurationofFigure3isgivenbythesequence(1,2,3,4,5,6,7,8).Thisconfigurationistheinitialconfiguration.Threebasictransformations,identifiedbytheletters`A',`B'and`C',canbeappliedtoasheet:'A':exchangethetopandbottomrow,'B':singlerightcircularshiftingoftherectangle,'C':singleclockwiserotationofthemiddlefoursquares.Belowisademonstrationofapplyingthetransformationstotheinitialsquaresgivenabove:A:87651234B:41235876C:17248635Allpossibleconfigurationsareavailableusingthethreebasictransformations.Youaretowriteaprogramthatcomputesaminimalsequenceofbasictransformationsthattransformstheinitialconfigurationabovetoas
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2030汽車新能源電池行業(yè)供需狀況分析及投資前景規(guī)劃研究報告
- 2025-2030汽車教練行業(yè)市場競爭行業(yè)態(tài)勢分析與市場營銷策略與行業(yè)未來發(fā)展
- 2025-2030汽車嵌入式系統(tǒng)技術研發(fā)與應用市場競爭格局分析報告
- 2025-2030汽車后市場服務連鎖經(jīng)營分析與發(fā)展規(guī)劃建議
- 2025-2030汽車后市場服務體系建設完善計劃與利潤增長模式創(chuàng)新分析
- 2025-2030汽車制造行業(yè)市場規(guī)模競爭格局要素組合投資條件研究分析評價計劃
- 2025-2030汽車制造業(yè)新能源技術研發(fā)與產業(yè)轉型升級評估規(guī)劃研究報告
- 2025-2030汽車共享行業(yè)市場發(fā)展趨勢及租賃系統(tǒng)運營管理報告
- 2025-2030汽車修理業(yè)行業(yè)發(fā)展現(xiàn)狀與資金操作規(guī)劃研究報告
- 2026年跨境營銷策劃公司董事會職責權限與決策管理制度
- 2025年宜昌市“招才興業(yè)”市直事業(yè)單位人才引進47人·重慶大學站筆試歷年典型考題(歷年真題考點)解題思路附帶答案詳解
- 2026海南交通投資控股公司秋招面筆試題及答案
- 2025年安徽理工大學馬克思主義基本原理概論期末考試模擬試卷
- 2025年大學大一(法學)法理學試題及答案
- 膽囊癌課件教學課件
- 廣西2025年高等職業(yè)教育考試全區(qū)模擬測試 能源動力與材料 大類試題及逐題答案解說
- 2026江蘇省公務員考試公安機關公務員(人民警察)歷年真題匯編附答案解析
- 超市冷庫應急預案(3篇)
- 5年(2021-2025)山東高考生物真題分類匯編:專題17 基因工程(解析版)
- 2025年10月自考00610高級日語(二)試題及答案
- 新華資產招聘筆試題庫2025
評論
0/150
提交評論