资源描述:
《中国石油大学第八章计算机作业(china university of petroleum eighth chapter computer homework)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、中国石油大学第八章计算机作业(ChinaUniversityofPetroleumeighthchaptercomputerhomework)8.1characterconversiondescribeExtractallthenumericcharactersinastring('0'...'9')andconvertittoanintegeroutput.inputAstringwiththecarriagereturnastheendmark(lessthan80characters).outputConvertsallnumericcharactersinastrin
2、g('0'...'9')toanintegerandoutputsit.#includeIntmain(){Charstr[80];Inti,m=0;Gets(STR);For(i=0;str[i];=' ';i++){If(str[i]<='9'&&str[i]>='0'){M=m*10+(str[i]-48);}}Printf("%d",m);}8.2mergestringsInputtwostringsthathavebeenarrangedinorderfromsmalltolarge,writeafunctionthatcombinestwo
3、strings,sothatthemergedstringisstillfromsmalltolargearrangement.Input:Twostringsthathavebeenarrangedinorder(ascending)Output:Anordered(ascending)stringmergedtogether#include#include#includeIntmain(){Chara[100],b[100],t;Intk,I,j;Gets(a);Gets(B);Strcat(a,B);K=strl
4、en(a);For(j=1;j<=k;j++)For(i=0;i=a[i+1]){T=a[i];A[i]=a[i+1];A[i+1]=t;}Puts(a);Return0;}8.3deleteduplicatecharactersBackground:Enterastringofnomorethan100,anddeletetheduplicatecharactersinthestring.Input:Enterastringtocheck,notmorethan100characterslong.Forexample:abacaeedabc
5、dcd.Output:Stringafterdeletingduplicatecharacters.Forexample:abced.#includeIntmain(){Chara[100],b[100];Intn,I,J,cnt=1;Gets(a);N=strlen(a);B[0]=a[0];For(i=1;i6、intf("");Return0;}8.4deletesthespecifiedcharacterinastringEntertwostringsS1andS2,deleteanycharactersinS2ins1.Forexample,S1:"abc123ad",S2:"A1",thenoutput"bc23d"".Input:twostringsS1andS2Output:thedeletedstringS1Requirement:Designanefficientalgorithm,justscaneverystring.Ifyouuseadvancedstrin
7、gconcatenation,andthensortingalgorithm,theefficiencyistoolow#includeIntmain(){Chara[100],b[100],c[100];Intm,N,I,J,k=0,P,q;Gets(a);Gets(B);N=strlen(a);M=strlen(B);For(i=0;i