




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
#include<stdio.h>#include<stdlib.h>#include<assert.h>#includeintdelete_sub_str(constchar*str,constchar*sub_str,char{assert(str!=NULL&&sub_str!=NULL);constchar*p,*q;charp=q=sub_str;t=result;intn,count=0;n=strlen(q);tmep=(char*)malloc(n+1);{if(strcmp(temp,q)==0){}{}}
p=p+n;*t=*p;returncount;}int{chars[100]=intnum=delete_sub_str(“123abc12de234fg1hi34j123k”,”123”,s);printf(“Thenumberofsub_stris%d\r\n”,num);printf(“Theresultstringis}2、環(huán)是一個數(shù)學的應用問題:已知n個人(以編號1,2,3...n分別表示)圍坐在一張圓桌周圍。從編號為k的人開始報數(shù),數(shù)到m人又從1數(shù)到m部出列。typedefstruct{intstructNodeLinkList*creat(int{LinkList*p,*q,*head;inti=1;p=(LinkList*)malloc(sizeof(LinkList));{q=(LinkList*)malloc(sizeof(LinkList));} /**/returnhead;}voidfun(LinkList*L,int{intLinkList*p,*s,*q;{ p=p-}}}int{LinkList*L;intn,m;return0;}3#include<stdio.h>#includeinthuiwen(char{inti,len,k=1;{{}}printf("%s\n",str);printf("%s數(shù)}void{charstr[100]={0};inti;intprintf("Inputastring:"); /*提示輸入Inputastring:*/scanf("%s",str); }4、數(shù)組比較(20 pare(intlen1,intarray1[],intlen2,int【輸入】intlen1:輸入被比較數(shù)組1數(shù)intarray1[]:輸入被比較數(shù)組intlen2:輸入被比較數(shù)組2intarray2[]:輸入被比較數(shù)組【輸出】【返回】型為1)intarray1[]={1,3,5},intlen1=={77,21,1,3,5},intlen2=2)intarray1[]={1,3,5},intlen1=={77,21,1,3,5,7},intlen2= pare(intlen1,intarray1[],intlen2,int{intfor(;len1>=0&&len2>=0;len1--,len2--{{}}return}int{intintarray1[]={1,3,5};intlen1=3;intarray2[]={77,12,1,3,5};intlen2=5;這
pare(len1,array1,len2,array2); pare(len1,array1[],len2array2[]);不//函數(shù)形參中只是傳得首地址,不能傳數(shù)printf("theresultis%d",}5、問輸入一個由隨機數(shù)組成的數(shù)列(數(shù)列中每個數(shù)均是大于0整數(shù),長度已知),和初始計數(shù)值m。從數(shù)列首位置開始計數(shù),計數(shù)到m將數(shù)列該位置數(shù)值替換計數(shù)值m,并將數(shù)列該位置數(shù)值出列,然后從下一位置從新開始計數(shù),直到數(shù)列所有數(shù)值出列為止。如果計數(shù)到達3,1,2,4,初始計數(shù)值m=7,從數(shù)列首位置開始計數(shù)(數(shù)值3)第一輪計數(shù)出列數(shù)字為2m=23,1,4,從數(shù)值4計數(shù)第二輪計數(shù)出列數(shù)字為3m=31,4,從數(shù)值1第三輪計數(shù)出列數(shù)字為1m=14,從數(shù)值4最后一輪計數(shù)出列數(shù)字為4,計數(shù)過程完成。voidarray_iterate(intlen,intinput_array[],intm,int【輸入】intlen:輸入數(shù)列的長度;intintput_array[]:輸入的初始數(shù)列intm:初始計數(shù)值【輸出】intoutput_array[]:輸出的數(shù)值出列順【返回】輸入:intinput_array[]={3,1,2,4},intlen=4,輸出:output_array[]=typedefstruct{intstructnode}node*creat(intlen,int{node*h,*s,*p;inti;{}p-return}voidarray_iterate(intlen,intinput_array[],int{node*q,*p,*s;intintoutput_array[4];{{p=p-}m=p-}for(j=0;j<=k;{}}int{intinput_array[]={3,1,2,4};intlen=4;intintarray_iterate(len,input_array,m,}6、號碼判斷(20分1、長度132、86頭3、號碼的每一位都是數(shù)字 號碼判斷的函數(shù)要求如 號碼合法,返回如 如 如 號碼不是以86打頭的,返回intverifyMsisdn(char*【輸入】char*inMsisdn,表示輸入的號碼字符串【輸出】【返回】判斷的結果,類型為int示輸入:inMsisdn869123456789“輸出:無返回:輸入:inMsisdn88139123456789“輸出:無返回:輸入:inMsisdn86139123456789“輸出:無返回:#defineLENGTHintverifyMsisdn(char{char*pchar=NULL;{{{}}
return2;}
returnreturnreturn}int{char*pchar=NULL;unsignedcharichar=0;intresult;{casecase1:case2: ";break;}result=verifyMsisdn(pchar);printf("resultis%d\n",result);}7、數(shù)組比較(20 pare(intlen1,intarray1[],intlen2,int【輸入】intlen1:輸入被比較數(shù)組1數(shù)intarray1[]:輸入被比較數(shù)組intlen2:輸入被比較數(shù)組2intarray2[]:輸入被比較數(shù)組【輸出】【返回】型為1)intarray1[]={1,3,5},intlen1=3,int={77,21,1,3,5},intlen2=2)intarray1[]={1,3,5},intlen1=3,int={77,21,1,3,5,7},intlen2= pare(intlen1,intarray1[],intlen2,int{intfor(;len1>=0&&len2>=0;len1--,len2--{{}}return}int{intintarray1[]={1,3,5};intlen1=3;intarray2[]={77,12,1,3,5};intlen2=5;pare(len1,array1,len2, pare(len1array1[],len2,array2[]);不能這//函數(shù)形參中只是傳得首地址,不能傳數(shù) printf("theresultis%d",}問題描述:輸入一個只包含個位數(shù)字的簡單四則運算表達式字符串,計算該表達式的值注:1、表達式只含+,-,*,/四則運算符,不含括號5情況intcalculate(intlen,char【輸入】intlen:字符串長度char*expStr:【輸出】【返回】結1)char*expStr=“1+4*5-8/3”2)char*expStr=#include<stdio.h>authorbytime:2011-09-usingnamespace pare(intlen1,intarray1[],intlen2,int{if(len1==len2){intcount=0;for(int{if(array1[i]!=array2[i])}return}elseif(len1<len2) pare(len1,array1,len1,array2+len2-}else }}voidarray_iterate(intlen,intinput_array[],intm,int{int*flag=newint[len];inthasout=0;//已經(jīng)出列的數(shù)字個數(shù)intstart=0;//開始的下標號intj=0; {if(flag[start {if(j==m)//已經(jīng)計數(shù)到m,當前start出{output_array[hasout]input_array[start];flag[start]=1; hasout++;if(hasoutlen)break;程j=0;m=}}startif(start==len)start=}delete[]}intcalculate(intlen,char{structcharopdata[200];inttop;opstack.top1;inti=0;//遍歷字符串的下標intt=0;//當前后綴表達式的長度charch=expStr[i];while{switch{casecase'-while(opstack.top!=-{expStr[t]=opstack.opdata[opstack.top];}opstack.opdata[opstack.top]=ch;casecasewhile(opstack.top!=-1&&(opstack.opdata[opstack.top]=='*'||opstack.opdata[opstack.top]=='/'){expStr[t]=opstack.opdata[opstack.top];}
opstack.opdata[opstack.top]=ch;expStr[t]=ch;ch=}while(opstack.top1{expStr[t]=opstack.opdata[opstack.top];} intnumeric[200];inttop;data.top=-1;ch=expStr[i];while{if(ch>='0'&&ch<='9'{data.numeric[data.top]=ch-'0';}elseif('+'=={inttmp=data.numeric[data.top-1]+data.numeric[data.top];data.numeric[data.top]=}elseif('-'=={inttmp=data.numeric[data.top-1]-data.numeric[data.top];data.numeric[data.top]=}elseif('*'=={inttmp=data.numeric[data.top-1]*data.numeric[data.top];data.numeric[data.top]=}elseif('/'=={if(data.numeric[data.top]=={printf("cannotbezeroofthedivide\n");}
inttmp=data.numeric[data.top-1]/data.numeric[data.top];data.numeric[data.top]=ch=}return}void{intarray1[]={1,3,5};intlen1=3;intarray2[]=intlen2=intcount= intinput_array[]={3,1,2,4};intlen=4;intm=7;int*output_array=newint[sizeof(input_array)/sizeof(int)];for(int{printf("%d}delete[]output_array;charexpStr[]="8/3*3";intresult=calculate(strlen(expStr),expStr);}9、選秀打分,分為專家評委和大眾評委,score[]數(shù)組里面每個評委打的分數(shù),judge_type[]里與score[]數(shù)組對應的評委類別,judge_type[i]1,表示專家評委,judge_type[i]2,表示大眾評委,n。打分規(guī)則如下:專家評委和眾評委的分數(shù)先分別取一個平均分(平均分取整),然后,總分=專家評委平均分 *0.6+大眾評委*0.4,總分取整。如果沒有大眾評委,則總分=專家評委平均分,總分取整。函數(shù)最終返回選手得分。 intcal_score(intscore[],intjudge_type[],intn)#defineN5intcal_score(intscore[],intjudge_type[],int{intexpert=0;intdazhong=0;intzongfen=0;inti;int{{}else}{}{}
return}int{intintjudge_type[N];intnumberlast=0;inti;printf("pleaseinputthe%dscore:\n",N);printf("pleaseinputthelevel(1:expert,2:dazhong)\n");printf("thelastscoreis%d\n",numberlast);return0;}則將數(shù)組中最大的元素放到output[]數(shù)組中間兩個位置偏右的那個位置上,然后再按從大到小的順序,依次在第一個位置的兩邊,按照例如:input[]={3,6,1,9, output[]={3,7,9,6, input[]={3,6,1,7, output[]={1,6,8,9,7,voidsort(intinput[],intn,int{inti,j;intk=1;inttemp;intmed;{{}}{{}}}int{
intintb[6]={0};for(inti=0;i<6;i++)return0;}優(yōu)函數(shù)scheduler功能task的任放到system_task組和user_task[]數(shù)組中(數(shù)組中元素的值是任務在task[]數(shù)組中的下標),并且優(yōu)先級高的任務排面,數(shù)組元素為-1表示結束。例如:task{0,30,155,1,80,300,170,40,99}system_task[]{0,3,1,71}={4,8,2,6,- voidscheduler(inttask[],intn,intsystem_task[],intuser_task[])voidscheduler1(inttask[],intn,intsystem_task[],int{inti;intj=0;int*p,*pp,*p_user,*pp_user;intindex=0;intcount,count2;intmin=0;intk=0;{{{}}else{{}}else}{{{}}}{{{}}}}int{inttask[9]={0,30,155,1,80,300,170,40,intsystem_task[9]={0};intuser_task[9]={0};return0;}12、從兩個數(shù)組的最后一個元素比較兩個數(shù)組中不同元素的個數(shù),array1[5]={77,21,1,3,5},array2[3]={1,3,5},從array1[4]們不同的元素為3。intcompare_array(intlen1,intarray1[],intlen2,intarray2intcompare_array(intlen1,intarray1[],intlen2,int{int{}{} printf("%d",array1[i]);printf("%d {}returnnum;}void{intintlen1=5,len2=3;}#include<stdio.h>intmain(){charstr[20],*p;intlength=0;printf(“Pleaseinputastring:”);{}printf(“Thelengthofstringis%d\n”,length);return0;}14、使用C是待替換的字符串,strReplace串。答案一#include<stdio.h>#includevoidStrReplace(char*strSrc,char*strFind,char*strReplace);#defineM100;void{charcharchars2[]="ggg";}voidStrReplace(char*strSrc,char*strFind,char*{inti=0;intj;intn=strlen(strSrc);intk=strlen(strFind);{{{{}}}答案二
else}}#include<stdio.h>#defineMAX100StrReplace(char*s,char*s1,char*s2){char*p;for(;*s;s++)for(p=s1;*p&&*p!=*s;p++);if(*p)*s=*(p-s1+s2);}}int{char chars1[MAX],s2[MAX];//s1換puts("Pleaseinputthestringfors:");scanf("%s",s);puts("Pleaseinputthestringfors1:");scanf("%s",s1);puts("Pleaseinputthestringfors2:");scanf("%s",s2);StrReplace(s,s1,puts("Thestringofsafterdisplaceis:");printf("%s\n",s);return}答案三#include<stdio.h>#include<stdlib.h>#include<string.h>#defineM100voidStrReplace(char*strSrc,char*strFind,char*strReplace);intmain(){charcharchars2[]="gggg";return0;}voidStrReplace(char*strSrc,char*strFind,char*{while(*strSrc!={if(*strSrc=={if(strncmp(strSrc,strFind,strlen(strFind))==0{}{
}{}
inti=strlen(strFind);intj=strlen(strReplace);printf("i=%d,j=%d\n",i,j);char*q=strSrc+i;printf("*q=%s\n",q);while((*strSrc++=*strReplace++)!='\0');printf("strSrc-1=%s\n",strSrc-1);printf("*q=%s\n",q);while((*strSrc++=*q++)!=}}}15、編寫一個程序實現(xiàn)功能:將字符串”ComputerSecience”賦給一個字符數(shù)組,然后從第一個字母開始間隔的輸出該串,用指針完成。#include<stdio.h>#include<string.h>intmain(){charstr[]=”ComputerScience”;intflag=1;char*p=str;{if(flag{}flag=(flag+1)%}return}是待替換的字符串,strReplace串。答案一#include<stdio.h>#includevoidStrReplace(char*strSrc,char*strFind,char*strReplace);#defineM100;void{charcharchars2[]="ggg";}voidStrReplace(char*strSrc,char*strFind,char*{inti=0;intj;intn=strlen(strSrc);intk=strlen(strFind);{{{{}}}答案二
else}}#include<stdio.h>#defineMAX100StrReplace(char*s,char*s1,char*s2){char*p;for(;*s;s++)for(p=s1;*p&&*p!=*s;p++);if(*p)*s=*(p-s1+s2);}}int{char chars1[MAX],s2[MAX];//s1換puts("Pleaseinputthestringfors:");scanf("%s",s);puts("Pleaseinputthestringfors1:");scanf("%s",s1);puts("Pleaseinputthestringfors2:");scanf("%s",s2);StrReplace(s,s1,puts("Thestringofsafterdisplaceis:");printf("%s\n",s);return}答案三#include<stdio.h>#include<stdlib.h>#include<string.h>#defineM100voidStrReplace(char*strSrc,char*strFind,char*strReplace);intmain(){charcharcharreturn}voidStrReplace(char*strSrc,char*strFind,char*{while(*strSrc!={if(*strSrc=={if(strncmp(strSrc,strFind,strlen(strFind))==0{}{
}{}
inti=strlen(strFind);intj=strlen(strReplace);printf("i=%d,j=%d\n",i,j);char*q=strSrc+i;printf("*q=%s\n",q);while((*strSrc++=*strReplace++)!='\0');printf("strSrc-1=%s\n",strSrc-1);printf("*q=%s\n",q);while((*strSrc++=*q++)!=}}}charstr1[20]={“o”},str2[20]={“World”};#includeint{charstr1[20]={“o”},str2[20]={“World”};char*p=str1,*q=str2;while(*p)p++;while(*q){*p=*q;}*p=‘\0’;printf(“%s\n”,str1);return}floatavescore(floatscore[],int{floatfloatintintfloatfor(int{ { return29.void{floatfloatprintf("thelastscoreis:%5.2f\n",lastscore);37.thelastscoreis voidjiou(inta[],int{int { { }}{{} }void{int}問題描述:輸入一個只包含個位數(shù)字的簡單四則運算表達式字符串,計算該表達式的值注:1、表達式只含+,-,*,/四則運算符,不含括號5情況intcalculate(intlen,char【輸入】intlen:字符串長度char*expStr:【輸出】【返回】結1)char*expStr=“1+4*5-8/3”2)char*expStr=“8/3*3”#includeauthorbytime:2011-09-usingnamespace pare(intlen1,intarray1[],intlen2,int{if(len1==len2){intcount=0;for(int{if(array1[i]!=array2[i])}return}elseif(len1<len2) pare(len1,array1,len1,array2+len2-}else }}voidarray_iterate(intlen,intinput_array[],intm,int{int*flag=newint[len];inthasout=0;//已經(jīng)出列的數(shù)字個數(shù)intstart=0;//開始的下標號intj=0; {if(flag[start {if(j==m)//已經(jīng)計數(shù)到m,當前start出{output_array[hasout]input_array[start];flag[start]=1; hasout++;if(hasoutlen)break;程j=0;m=}}startif(start==len)start=}delete[]}intcalculate(intlen,char{structcharopdata[200];inttop;opstack.top1;inti=0;//遍歷字符串的下標intt=0;//當前后綴表達式的長度charch=expStr[i];while{switch{casecase'-while(opstack.top!=-{expStr[t]=opstack.opdata[opstack.top];}opstack.opdata[opstack.top]=ch;casecasewhile(opstack.top!=-1&&(opstack.opdata[opstack.top]=='*'||opstack.opdata[opstack.top]=='/'){expStr[t]=opstack.opdata[opstack.top];}
opstack.opdata[opstack.top]=ch;expStr[t]=ch;ch=}while(opstack.top1{expStr[t]=opstack.opdata[opstack.top];} intnumeric[200];inttop;data.top=-1;ch=expStr[i];while{if(ch>='0'&&ch<='9'{data.numeric[data.top]=ch-'0';}elseif('+'=={inttmp=data.numeric[data.top-1]+data.numeric[data.top];data.numeric[data.top]=}elseif('-'=={inttmp=data.numeric[data.top-1]-data.numeric[data.top];data.numeric[data.top]=}elseif('*'=={inttmp=data.numeric[data.top-1]*data.numeric[data.top];data.numeric[data.top]=}elseif('/'=={if(data.numeric[data.top]=={printf("cannotbezeroofthedivide\n");}
inttmp=data.numeric[data.top-1]/data.numeric[data.top];data.numeric[data.top]=ch=}return}void{intarray1[]={1,3,5};intlen1=3;intarray2[]=intlen2=intcount= intinput_array[]={3,1,2,4};intlen=4;intm=7;int*output_array=newint[sizeof(input_array)/sizeof(int)];for(int{printf("%d}delete[]output_array;charexpStr[]="8/3*3";intresult=calculate(strlen(expStr),expStr);}21、選秀打分,分為專家評委和大眾評委,
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度員工自愿離職后創(chuàng)業(yè)投資引導與支持協(xié)議
- 二零二五年度高空作業(yè)安全責任協(xié)議書(高空設備安裝與調(diào)試)
- 2025年度貸款合同簽訂流程與電子簽章技術應用指南
- 二零二五年度環(huán)保設備維護個人勞務用工合同
- 高考志愿填報與院校溝通2025年度合同
- 2025年度水上樂園綜合運營管理服務合同
- 中醫(yī)師承關系合同書(2025年度中醫(yī)理論教學)
- 二零二五年度物流倉儲配送一體化承包合同
- 2025年度綠色建筑認證與設計合同
- 多重耐藥菌的防控
- 裕興新概念英語第二冊筆記第42課
- 簡明新疆地方史趙陽
- 狹窄性腱鞘炎中醫(yī)臨床路徑及表單
- Q∕SY 19001-2017 風險分類分級規(guī)范
- 智慧消防綜合解決方案
- 市場營銷組合策略及營銷戰(zhàn)略課件
- 信息技術基礎ppt課件(完整版)
- DGJ 08-70-2021 建筑物、構筑物拆除技術標準
- 2022年義務教育語文課程標準(2022版)解讀【新課標背景下的初中名著閱讀教學質(zhì)量提升思考】
- 屋面網(wǎng)架結構液壓提升施工方案(50頁)
- 第6章向量空間ppt課件
評論
0/150
提交評論