C++程序设计经典300例.docx
- 文档编号:30744373
- 上传时间:2023-08-20
- 格式:DOCX
- 页数:14
- 大小:17.71KB
C++程序设计经典300例.docx
《C++程序设计经典300例.docx》由会员分享,可在线阅读,更多相关《C++程序设计经典300例.docx(14页珍藏版)》请在冰豆网上搜索。
C++程序设计经典300例
1*******************************
#include
usingnamespacestd;
intmain()
{
inti=1;eight { r=tree[i].weight; a=i; } } for(i=0;i { if((tree[i].weight =a)&&(tree[i].parent==-1)) { s=tree[i].weight; b=i; } } } h_num=0;h||(node[j].ch>='a'&&node[j].ch<='z'&&str[i]+32==node[j].ch)) break;h_num++; elseh=str[i]+32; else node[j].ch=str[i]; node[j].ch_num++; char_type_num++;h_num ch_temp=node[j].ch; node[j].ch_num=node[j+1].ch_num; node[j].ch=node[j+1].ch; node[j+1].ch_num=temp; node[j+1].ch=ch_temp; } } } for(i=0;i huffTree*huff=newhuffTree[2*char_type_num-1];child=-1; huff[i].parent=-1; huff[i].rchild=-1; huff[i].flag=-1; } for(j=0;j } intmin1,min2; for(intk=char_type_num;k<2*char_type_num-1;k++)arent=k; huff[min2].parent=k; huff[min1].flag="0"; huff[min2].flag="1"; huff[k].lchild=min1; huff[k].rchild=min2; huff[k].weight=huff[min1].weight+huff[min2].weight; } for(i=0;i { temp=huff[i]; while (1) { code[i]=+code[i]; temp=huff[]; if==-1) break; } } cout<<"字符串的每个字符huffman编码为: "< for(i=0;i cout< cout<<"整个字符串的huffman编码为: "< for(i=0;i { for(j=0;j { if(str[i]==node[j].ch) cout< } } *********************************************** #include usingnamespacestd; intarray_039[10]={0,1,2,3,4,5,6,7,8,9}; voidbinary_search(intleft,intright,intvalue) { intsearch_index; search_index=(left+right)/2;.9报数时计数变量 yijiao_count=0;h_num,"00");h_name,"微信,这么玩才赚钱"); strcpy(Book[0].ch_author,"王易"); strcpy(Book[0].ch_publisher,"机械工业出版社"); strcpy(Book[1].ch_num,"01"); strcpy(Book[1].ch_name,"微信营销解密"); strcpy(Book[1].ch_author,"程小永"); strcpy(Book[1].ch_publisher,"机械工业出版社"); strcpy(Book[2].ch_num,"02"); strcpy(Book[2].ch_name,"C++Primer中文版(第5版)"); strcpy(Book[2].ch_author,"(美)李普曼、拉乔伊"); strcpy(Book[2].ch_publisher,"电子工业出版社"); strcpy(Book[3].ch_num,"03"); strcpy(Book[3].ch_name,"疯狂Android讲义"); strcpy(Book[3].ch_author,"李刚"); strcpy(Book[3].ch_publisher,"电子工业出版社"); strcpy(Book[4].ch_num,"04"); strcpy(Book[4].ch_name,"C程序设计第四版"); strcpy(Book[4].ch_author,"谭浩强"); strcpy(Book[4].ch_publisher,"清华大学出版社"); cout<<"------------------------图书管理系统---------------------"< cout<<"现库存图书有00-04号,图书信息有以下内容: "< cout<<"图书编号---------图书名---------图书作者--------图书出版社"< intchoice; intdel_num;h_num>>Book[number].ch_name>>Book[number].ch_author>>Book[number].ch_publisher; break; case2: h_author,""); strcpy(Book[del_num-1].ch_name,""); strcpy(Book[del_num-1].ch_publisher,""); strcpy(Book[del_num-1].ch_num,""); } else { for(inti=del_num-1;i { strcpy(Book[i].ch_author,Book[i+1].ch_author); strcpy(Book[i].ch_name,Book[i+1].ch_name); strcpy(Book[i].ch_publisher,Book[i+1].ch_publisher); } } break; case3: h_num>>Book[modify_num-1].ch_name>>Book[modify_num-1].ch_author>>Book[modify_num-1].ch_publisher; } break; case4: h_num<<""< break; default: break; } } return0; } 49************************************************** #include usingnamespacestd; < 天才;G: 自卑;H: 美貌;I: 花痴; J: 英勇;K: 臭屁;L: 卖国;M: 饭桶;N: 变态;O: 热血;P: 嗜血;Q: 旷世;R: 守财; S: 血手;T: 平庸;U: 爱国;V: 亡命;W: 暴力;X: 多情;Y: 自恋;Z: 逍遥 结字(最后字): A: 道士;B: 和尚;C: 财主;D: 屠夫;E: 马夫;F: 嫔妃;G: 兵士;H: 酒鬼;I: 地主; J: 医师;K: 农夫;L: 稳婆;M: 更夫;N: 书生;O: 乞丐;P: 帝或后;Q: 臣相;R: 流氓; S: 戏子;T: 土匪;U: 守墓人;V: 媒婆;W: 庖丁;X: 诗人;Y: 歌妓;Z: 讼师 →看看你是何许人也*/ #include #include usingnamespacestd; voidname_test(char*ch,string&str) { stringstr_first[26]={"曹魏","东吴","蜀汉","土番","秦宋","大金","明朝","鲜卑","五代",\ "晚清","西周","赵国","大辽","夏商","战国","春秋","东晋","羌族",\ "民国","齐国","闽国","南燕","大理","西凉","南唐","蒙古"}; stringstr_mid[26]={"阴毒","疯骚","猥琐","豪门","白痴","天才","自卑","美貌","花痴",\ "英勇","臭屁","卖国","饭桶","变态","热血","嗜血","旷世","守财",\ "血手","平庸","爱国","亡命","暴力","多情","自恋","逍遥"}; stringstr_late[26]={"道士","和尚","财主","屠夫","马夫","嫔妃","兵士","酒鬼","地主",\ "医师","农夫","稳婆","更夫","书生","乞丐","帝或后","臣相","流氓",\ "戏子","土匪","守墓人","媒婆","庖丁","诗人","歌妓","讼师"}; for(inti=0;i<3;i++) { if(ch[i]<='z'&&ch[i]>='a') ch[i]-=(32+65);< } } voidmain() { intxx=100,yy=200; print_int(xx,yy);开2.关闭"< cin>>receive_str; receive_code(receive_str); } 97************************************************************ #include usingnamespacestd; /*一辆汽车每小时可行驶90公里,每跑两小时休息半小时 问该车工作8小时能行驶的里程*/ floatmile(floata,floatb,floatc,intd) { floatresult=;//总里程 boolflag=true; while(flag==true)//时间没用完 { if(a>=d) result+=d*b; else { flag=false; if(a<=d) result+=a*b; else result+=b; } a-=(c+d);//先减 } returnresult; } voidmain() { floatwhole_hour=8;//总时间 floatmile_per_hour=90;//每小时里程 floatrelax=;//休息时间 intdiff=2;//工作两小时休息 cout<<"汽车8小时内跑"< } 98************************************************************** #include usingnamespacestd; voidfenlei(int*a,int*b,intlength) { for(inti=0;i { if(a[i]==0) b[1]++; elseif(a[i]==1) b[0]++; } } voidmain() { intsex_banji[10]={1,1,0,0,0,1,0,0,1,1};//0-female,1-male intnum[2]={0};//男女人数,元素0为男,元素1为女 fenlei(sex_banji,num,10); cout<<"男女人数分别为: "< } 99******************************************************************** #include usingnamespacestd; int*fenpei(int*a,int*b,intnum) { int*remain=newint[num]; for(inti=0;i remain[i]=a[i]%b[i]; returnremain; } voidmain() { intfruit[10];//10种水果各自个数 intnum_people[10];//每种水果对应分配人数 int*premain=NULL; for(inti=0;i<10;i++) { fruit[i]=100*i+1; num_people[i]=i+1; } premain=fenpei(fruit,num_people,10); cout<<"分配水果后各自还剩个数: "< for(inti=0;i<10;i++) cout< delete[]premain; premain=NULL; } 100******************************************************** #include #include<> usingnamespacestd; #defineM30 voiddelZero(char*ch,intsize) { intlength=size; for(inti=0;i { if(ch[i]=='') { for(intj=i;j ch[j]=ch[j+1]; length--; i--; } } ch=newchar[length]; } voidmain() { char*ch_test; ch_test=newchar[M]; strcpy(ch_test,"akdfljakdf"); cout<<"试验的字符数组为: "< delZero(ch_test,M); cout<<"整理内存后: "< cout< free(ch_test); ch_test=NULL; } F********************************************** #include usingnamespacestd; voidsequence(char**ch,introw,intcol) { for(inti=0;i { for(intj=i+1;j { if(ch[i][0]>ch[j][0]) { char*ch1=newchar[col]; strcpy(ch1,ch[i]); strcpy(ch[i],ch[j]); strcpy(ch[j],ch1); } } } } voidmain() { intm=5,n=50; cout<<"现有5本英文图书,名字分别如下: "< char**ch=newchar*[m]; for(inti=0;i ch[i]=newchar[n]; strcpy(ch[0],"C++Primer"); strcpy(ch[1],"MoreEffectiveC++"); strcpy(ch[2],"EssentialC++"); strcpy(ch[3],"ImperfectC++"); strcpy(ch[4],"HeadFirstJava"); for(inti=0;i<5;i++) cout< cout< "< sequence(ch,m,n); for(inti=0;i<5;i++) cout< delete[]ch; ch=NULL; }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+ 程序设计 经典 300
![提示](https://static.bdocx.com/images/bang_tan.gif)