版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
注:下列程序本人確保一定對(duì)的,有一部分是我在網(wǎng)上找到的,并不全是本人實(shí)的好孩紙,絕對(duì)不騙人財(cái)富值,相信我吧,這些程序你值得擁有。typedefstructfloatcoef;intexpn;//指數(shù)值structnode*next;voidstart()//{printf("兩個(gè)一元多項(xiàng)式的相加,相減,相乘:\n");printf("請(qǐng)選擇操作printf("0.退出printf("3.兩個(gè)一元多項(xiàng)式相減}voidinsert(PLOY*head,PLOY*inpt)//{PLOY*pre,*now;intsignal=0;pre=head;//pre定義為現(xiàn)在的前一種鏈節(jié)if(pre->next==NULL){pre->next=inpt;}{{if(inpt->expn<now->expn)//{if(now-{}{}}if(inpt-{}{free(inpt);{}}}}}PLOY*creat(charch)//{PLOY*head,*inpt;floatx;inthead=(PLOY*)malloc(sizeof(PLOY));printf("請(qǐng)輸入一元多項(xiàng)式%c:(00~)\n",ch);scanf("%f%d",&x,&y);{inpt=(PLOY*)malloc(sizeof(PLOY));insert(head,inpt);//否則就查找位置并且插入新鏈節(jié)printf("請(qǐng)輸入一元多項(xiàng)式%c的下一項(xiàng):(以00~)\n",ch);scanf("%f%d",&x,&y);}return}PLOY*minuscreat(charch)//{PLOY*head,*inpt;floatx;inthead=(PLOY*)malloc(sizeof(PLOY));printf("請(qǐng)輸入一元多項(xiàng)式%c:(00~)\n",ch);scanf("%f%d",&x,&y);{inpt=(PLOY*)malloc(sizeof(PLOY));insert(head,inpt);//否則就查找位置并且插入新鏈節(jié)printf("請(qǐng)輸入一元多項(xiàng)式%c的下一項(xiàng):(以00~)\n",ch);scanf("%f%d",&x,&y);}return}PLOY*addPLOY(PLOY*head,PLOY*pre)//PLOY*inpt;intflag=0;{if(pre-flag=1;{pre=pre-inpt=(PLOY*)malloc(sizeof(PLOY));}//否則把目前"g(x)"的鏈節(jié)插入到"F=(x)"}return}PLOY*byPLOY(PLOY*head1,PLOY*head2)//PLOY*inpt,*res,*pre;intres=(PLOY*)malloc(sizeof(PLOY));head1=head1-{if(pre-{pre=head2;}{flag=1;}pre=pre-inpt=(PLOY*)malloc(sizeof(PLOY));insert(res,inpt);//把目前"g(x)"的鏈節(jié)插入到"F=(x)"}return}voidprint(PLOY*fun)//{PLOY*printing;intflag=0;printing=fun->next;//正在被打印的鏈節(jié)if(fun->next==NULL)//如果函數(shù)為空打印{}{printf("+");//為正數(shù)時(shí)打印"+"號(hào)if(printing->coef==1);"1"就不用打印系數(shù)了elseif(printing->coef==-1)printf("1"就打印"-"號(hào)就行了printf("%f",printing->coef);if(printing->expn!=0)printf("x^%d",printing->expn);//如果指數(shù)為"0"elseif((printing->coef==1)||(printing->coef==-1))if(printing-flag=1;printing=printing-}}voidminusprint(PLOY*fun)//{PLOY*printing;intflag=0;printing=fun->next;//正在被打印的鏈節(jié)if(fun->next==NULL)//如果函數(shù)為空打印{}{printf("-");//為正數(shù)時(shí)打印"-"號(hào)if(printing->coef==-1);1"就不用打印系數(shù)了elseif(printing->coef==1)printf(""1"就打印"-"號(hào)就行了printf("+%f",-printing->coef);if(printing->expn!=0)>expn);//如果指數(shù)為"0"elseif((printing->coef==1)||(printing->coef==-1))if(printing-flag=1;printing=printing-}}void{PLOYintsign=-1;{{case0:break;case1:{f=creat('f');//輸入多項(xiàng)式f(x)g=creat('g');g(x)f=addPLOY(f,g);sign=-1;//復(fù)位標(biāo)志start();}case{f=creat('f');//輸入多項(xiàng)式f(x)g=creat('g');g(x)f=byPLOY(f,g);sign=-1;//復(fù)位標(biāo)志start();}case{f=creat('f');//輸入多項(xiàng)式f(x)g=minuscreat('g');g(x)f=addPLOY(f,g);sign=-1;//復(fù)位標(biāo)志start();}{}}}}迷宮求解(建.cpp以一種m*n的長(zhǎng)方形矩陣表達(dá)迷宮,0和1有#include<stdio.h>#include<stdlib.h>#defineM15#defineN15structmarkintx;intstructElement{intx,y;//x行,yintd;//dtypedefstructLStack{ElementstructLStackintInitStack(PLStack&S)//構(gòu)造空棧return}intStackEmpty(PLStackS)//return1;return0;intPush(PLStack&S,Elemente)//PLStackp;p-return}intPop(PLStack&S,Element&e)PLStackp;{return1;}return0;}/***************求迷宮途徑函數(shù)voidMazePath(structmarkstart,structmarkend,intmaze[M][N],int{inti,j,d;inta,b;Elementelem,e;PLStackS1,S2;maze[start.x][start.y]=2;elem.d=-1;1while(!StackEmpty(S1)){d=elem.d+1;//下一種方向while(d<4){if(a==end.x&&b==end.y&&maze[a][b]==0){elem.d=886;//方向輸出為-1printf("\n0=1=2=3=886為則走出迷宮\n\n通路while(S1)}printf("--}return;break,但發(fā)現(xiàn)出錯(cuò),exit又會(huì)}if(maze[a][b]==0){maze[a][b]=2;Push(S1,elem);i=a;//下一點(diǎn)轉(zhuǎn)化為目前點(diǎn)d=-}}printf("沒(méi)有找到能夠走出此迷宮的途徑\n");voidinitmaze(intmaze[M][N]){intintm,n;printf("m=");printf("n=");printf("\n請(qǐng)輸入迷宮的各行各列:\n用空格隔開(kāi),0代表路,1for(i=0;i<=m+1;i++){}{}for(i=0;i<=m+1;i++){printf("%d",maze[i][j]);}}void{intstructmarkstart,end;//start,end入口和出口的坐標(biāo)intadd[4][2]={{0,1},{1,0},{0,-1},{-initmaze(sto);//MazePath(start,end,sto,add);//findpath求迷宮途徑//從程序里調(diào)用“pause”命令,在命令行上輸出一行類似于“Pressanykeytoexit”的字,等待顧客按一種鍵,然后返回}3)#defineINFINITY10000/*無(wú)窮大*/#defineMAX_VERTEX_NUM40#defineMAX40typedefstructArCell{intadj;typedefstructcharname[30];intcharintroduction[100];//typedefstruct{infotypevexs[MAX_VERTEX_NUM];AdjMatrixarcs;intMGraphb;voidcmd();MGraphInitGraph();voidMenu();voidBrowser(MGraphvoidShortestPath_DIJ(MGraph*G);voidFloyd(MGraph*G);voidSearch(MGraph*G);intLocateVex(MGraph*G,char*v);MGraph*CreatUDN(MGraph*G);voidprint(MGraph*G);voidmain(){system("colorsystem("modecon:cols=140lines=130");}voidcmd(){inti;{{casecase2:system("cls");ShortestPath_DIJ(&b);Menu();break;case3:system("cls");Floyd(&b);Menu();break;case4:system("cls");Search(&b);Menu();break;case5:exit(1);break;}}}MGraph{MGraphG;inti,j;strcpy(G.vexs[2].introduction,"strcpy(G.vexs[3].name,"strcpy(G.vexs[3].introduction,"strcpy(G.vexs[9].introduction,"returnG;}//InitGraphendvoidMenu(){printf("\n\n");printf("??????????????????????\n");printf("?1.瀏覽校園全景printf("?2.查看全部游覽路線printf("3.選擇出發(fā)點(diǎn)和目的地,顯示一條最短途徑?\n");printf("?4.查看景點(diǎn)信息?\n");printf("?5.退出系統(tǒng)?\n");printf("??????????????????????\n");printf("}voidBrowser(MGraph{intv;printf("?for(v=0;v<G-printf("?%-4d?%-16s?%-58s?\n",G->vexs[v].num,G-printf("\n");printf("?\n");printf("printf("18\n");printf("??????????????????\n");printf("printf("printf("\n");printf("?\n");printf("printf("\n");printf("?\n");printf("printf("西區(qū)超市???11號(hào)教學(xué)樓????????????荷花池}//迪杰斯特拉算法來(lái)計(jì)算出起點(diǎn)到各個(gè)頂點(diǎn)之間的最短途徑,v0voidShortestPath_DIJ(MGraph*G){intv,w,i,min,t=0,x,flag=1,v0;intfinal[20],D[20],p[20][20];{if(v0<0||v0>G-{}}for(v=0;v<G-{{}}{}}for(v=0;v<G-{if(v0!=v)printf("%s",G->vexs[v0].name);{if(p[v][w]&&w!=v0)printf("-->%s",G->vexs[w].name);}if(t>G->vexnum-1&&v0!=v)printf("總路線長(zhǎng)}}//ShortestPath_DIJendvoidFloyd(MGraph*G){intv,u,i,w,k,j,flag=1,p[10][10][10],D[10][10];for(w=0;w<G-{{}}for(w=0;w<G-}{if(k<0||k>G->vexnum||j<0||j>G-{}}printf("-->%s",G-printf("-->%s",G-printf("總路線長(zhǎng)}//FloydvoidSearch(MGraph{intk,flag=1;{if(k<0||k>G-{}printf("?printf("?%-4d?%-16s?%-56s?\n",G->vexs[k].num,G-}//SearchintLocateVex(MGraph*G,char*v)intc=-returnc;}MGraph*CreatUDN(MGraph*G)//{intchar{printf("scanf("%d",&G->vexs-scanf("%s",G->vexs-}for(j=0;j<G-{printf("第%d條邊printf("{G-G->arcs[j][i]=G-}}return}voidprint(MGraph{intfor(v=0;v<G-for(w=0;w<G-{printf("?");elseprintf("%-7d",G->arcs[v][w].adj);}}一共有m個(gè)女生,有n個(gè)男生(且m?n),現(xiàn)要開(kāi)一種舞會(huì),男女分別編號(hào)坐在舞下:#definequeuesizetypedefstruct{charname[20];//定義一種長(zhǎng)度為20charsex;char變量sex,用來(lái)表達(dá)性別,規(guī)定m表達(dá)男性,f表達(dá)女性}person_type;typedefstruct{person_type*qBase;intfront;intrear;voidinit_queue(cir_queue*q){q->qBase=(person_typeif(!q->qBase)//如果q->qBase為0則創(chuàng)立失敗,退出程序{exit(-1);//立刻終止程序}q->front=q->rear=NULL;boolfull_queue(cir_queue*q)//為滿返回true,否則返回if((q->rear+1)%queuesize==q->front)returntrue;return}boolempty_queue(cir_queue*q)//if(q->front==q->rear)returntrue;return}voiden_queue(cir_queue*q,person_typep)//進(jìn)隊(duì)函數(shù),使p{}else{q->qBase[q-q->rear=(q->rear+1)%queuesize;}}person_typede_queue(cir_queue*q)//出隊(duì)函數(shù),用pperson_typep;if(empty_queue(q))//{}else{p=q->qBase[q-returnp;}}intlength_queue(cir_queue*q)//求循環(huán)隊(duì)列元素個(gè)數(shù){returnq->rear-q->frontperson_typequeue_front(cir_queue*q)//{}returnq->qBase[q->front];voiddancepartners(cir_queuefemaledancer,cir_queuemaledancer,intlun)//舞伴配對(duì)函數(shù){intmlength_queue(&femaledancer);intn=length_queue(&maledancer);//計(jì)算男隊(duì)人數(shù)for(intj=1;j<=lun;++j)//forif(m>n)//{person_typep;person_typeq;person_type printf("第%d輪配對(duì)狀況for(inti=1;i<=n;++i)//for{q=de_queue(&femaledancer);en_queue(&femaledancer,q);}printf("女隊(duì)中第一種等待的是}elseif(m<n){person_typep;person_typeq;person_type for(inti=1;i<=m;++i){en_queue(&femaledancer,q);}printf("男隊(duì)中第一種等待的是}else{person_typep;person_type for(inti=1;i<=m;++i){q=de_queue(&femaledancer);}printf("沒(méi)有人剩余}}}intgac(intm,intw,intn)//求出與y號(hào)女生會(huì)在第nintx,z;{if(z>m)z=z-m;}elsex=(w*n-returnx;}void{person_typeinti,num,m,w;printf("輸入編號(hào)和性別(用m表達(dá)男性,用f\n7\nm\n");{}cir_queuemaledancer,femaledancer;//定義兩個(gè)循環(huán)隊(duì)列構(gòu)造體init_queue(&femaledancer);//調(diào)用init_queue()函數(shù)置空隊(duì)列{p=dancers[i];//構(gòu)造體整體賦值{}else//男的進(jìn)隊(duì)列{}}int{ printf("主菜單printf("1.輸出每曲配對(duì)狀況\n");printf("3.退出 printf("{case1:dancepartners(femaledancer,maledancer,n);break;case2:{int{{printf("他們會(huì)在第%d曲跳舞}}case}}}?運(yùn)算符限定于加、減、乘、除四種運(yùn)算,請(qǐng)驗(yàn)證體現(xiàn)式與否書(shū)寫(xiě)正當(dāng),如-*5#include<stdio.h>/*庫(kù)文獻(xiàn)包含*/#include<string.h>/*用于字符串操作*/#include<stdlib.h>/*用于exit函數(shù)*/intcheck(charchar*c:輸入的字符串若沒(méi)有,則返回1,intcheck(char{intk=0;{if((*c>='0'&&*c<='1000')||*c=='+'*c=='-'||*c=='*'||*c=='/'*c=='.'||*c=='('||*c==')'{}{printf("inputerror,therehavethecharnotthemathexpressionreturn0;//返回參數(shù),0:}elseif(*c==')')}{printf("inputerror,thereisnothavecorrectbracket'()'!\n");return0;//返回參數(shù),0:字符串中有不符合規(guī)定的字符}return1;//返回參數(shù),1:voidmove(char*f,double*s,intchar*f:運(yùn)算符數(shù)組double*s:intp:目前運(yùn)算符數(shù)組位置。傳入值p若為則目前符號(hào)的數(shù)組位置為f[3]=f[3+1].......f[len-2]=f[len-1]f[len-1]='\0';s[i]=s[i+1].......s[len-1]=s[len]voidmove(char*f,double*s,intp){inti=0,len=strlen(f);/*將已經(jīng)運(yùn)算過(guò)的符號(hào),空出來(lái)的位置用背面的符號(hào)來(lái)填充}f[len-}doubleconvnum(charchar*c:由數(shù)字和小數(shù)點(diǎn)構(gòu)成的字符,用以轉(zhuǎn)換成double型的數(shù)值。將輸入的字符串先將其小數(shù)點(diǎn)以前的部分復(fù)制到temp[]若有小數(shù)點(diǎn),則將小數(shù)點(diǎn)之后的數(shù)值,也就是小數(shù)部分先進(jìn)行計(jì)算,值存入中計(jì)算完畢后,再對(duì)整數(shù)部分進(jìn)行計(jì)算,值加上小數(shù)部分的值,存入numdoubleconvnum(char{doublenum=0.0;doublea=1.0;inti=0,p=0,len=0;chartemp[100];inttempi=0;intintf=1;/*正負(fù)符號(hào)批示器,若為1則為正數(shù),為,1,此數(shù)為負(fù)數(shù)*/if(c[0]=='-{}for(i=start;i<len;{{}temp[tempi++]=c[i];/*將整數(shù)部分復(fù)制到temp[]中}{for(i=p+1;i<len;i++)/*將小數(shù)部分計(jì)
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 房屋買賣合同誠(chéng)信承諾書(shū)3篇
- 政府采購(gòu)辦公設(shè)備合同3篇
- 工業(yè)煤氣供應(yīng)與安全合同3篇
- 斷橋鋁門(mén)窗安裝合同3篇
- 教育機(jī)構(gòu)店長(zhǎng)任職合同3篇
- 常用塔吊用工勞務(wù)合同3篇
- 摩托車買賣合同電子版3篇
- 攝像服務(wù)合同3篇
- 控?zé)煆奈易銎?篇
- 按月租房合同范本簡(jiǎn)單版3篇
- 《行動(dòng)研究法》課件
- 云南省昆明市西山區(qū)2023-2024學(xué)年三年級(jí)上學(xué)期期末語(yǔ)文試卷
- 腸梗阻病人護(hù)理查房課件中醫(yī)
- 試生產(chǎn)檢查準(zhǔn)備表
- 月下獨(dú)酌(其一)李白
- 《大學(xué)物理學(xué)》精美課件(全)
- 七年級(jí)上冊(cè)數(shù)學(xué)壓軸題幾何試卷(帶答案)
- 網(wǎng)絡(luò)安全保密教育知識(shí)普及培訓(xùn)課件
- 家長(zhǎng)會(huì)課件:初二上期家長(zhǎng)會(huì)課件
- 接待上級(jí)領(lǐng)導(dǎo)工作總結(jié)
- 著色滲透探傷檢測(cè)報(bào)告
評(píng)論
0/150
提交評(píng)論