




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验二栈和队列的基本操作实现及其应用一、实验目的1、熟练掌握栈和队列的基本操作在两种存储结构上的实现。2、会用栈和队列解决简单的实际问题。二、实验内容(可任选或全做)题目一、试写一个算法,判断依次读入的一个以@为结束符的字符序列,是否为回文。所谓“回文“是指正向读和反向读都一样的一字符串,如“321123”或“ableelba”相关常量及结构定义:#defineSTACK_INIT_SIZE100#defineSTACKINCREMENT10#defineOK1#defineERROR0typedefintSElemType;//栈类型定义typedefstructSqStack {SElemType*base;SElemType*top;intstacksize;}SqStack;设计相关函数声明:判断函数:intIsReverse()栈:intInitStack(SqStack&S)intPush(SqStack&S,SElemTypee)intPop(SqStack&S,SElemType&e)intStackEmpty(s)题目二、编程模拟队列的管理,主要包括:出队列、入队、统计队列的长度、查找队列某个元素e、及输出队列中元素。[实现提示]:参考教材循环队列的有关算法,其中后两个算法参考顺序表的实现。题目三、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题目六(选作考查数组知识)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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 高中生生命安全教育:守护成长之路
- 网络工程课程设计答辩
- 茶叶美术教案中班课件
- 2025国内借款合同范本2
- 2025标准房屋租赁合同样本模板
- 2025国内技术转让合同样本下载
- 2025宁夏瑞丰农业科技有限公司稻米种植收购合同
- 2025鞋类采购合同协议样本
- 2025合作协议合同范本模板
- 2025家庭装修合同书简化版装饰工程合同书
- 所得税会计试题及答案
- 2025年保安员职业技能考试笔试试题(700题)附答案
- 《知不足而后进 望山远而力行》期中家长会课件
- 专题09 乡村和城镇-五年(2019-2023)高考地理真题分项汇编(解析版)
- 2025年第三届天扬杯建筑业财税知识竞赛题库附答案(201-300题)
- T-NKFA 015-2024 中小学午休课桌椅
- 课题开题报告:推进家校社协同育人研究
- 2025春新七年级道德与法治下册全册知识点
- Unit 9 Active learning 教学设计-2023-2024学年高中英语北师大版(2019)必修第三册
- 渔场基地建设实施方案
- 《食源性病原体》课件
评论
0/150
提交评论