欢迎来到天天文库
浏览记录
ID:53413
大小:413.50 KB
页数:49页
时间:2017-04-29
《《C++程序设计》习题解答.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、C++程序设计习题解答(王挺)杂项1背包问题1趣味题1打印万年历2期末考试题3求解1□23□4□56□7□8□9=1004Chapter44P103T04104P103T04114P103T04125P103T04135输出不大于的Fibonacci数列5Stein算法求最大公约数--移位法5P102T04156P102T04166P102T04176P102T04197P102T04207P102T04217Chapter57p136T5.57p136T5.68p136T5.68p136T5.108p136T5.118p137T5.149p137T5.169p137T5.199Ch
2、apter69求组合算法9P159T6.310P159T6.410P159T6.410p159T6.1111p159T6.1211p159T6.1811p159T6.2012Chapter712p195T70612p195T70712p195T70812p195T70913P195T71014P195T71114P196T71314Chapter815p222T80315p222T08030415p222T8517p222T8060917附加18IIC++程序设计习题解答(王挺)Chapter918P241T9.118P241T9.219P241T9.320P241T9.521补充2
3、2Chapter1123p288T11.223P289T11.923//使用结构实现栈24//利用类实现栈数据结构25Chapter1226P305T120426p305T120527P306T120627P306T120729P306T120829Chapter1330P334T13附加题30P334T130331P334T130432P335T130533P335T130634p335T130734p336T130835P336T130936向量矩阵综合应用37Chapter1440P373T140540Chapter1642P422T160242P422T160342P423T
4、160543P422T1605-243Chapter1744P436T170644P436T170745P436T170945P436T171045IIC++程序设计习题解答(王挺)杂项/*背包问题背包问题的求解,求解除所有的可能解法,非递归*/#include#includeusingnamespacestd;typedefintDataElem;classStack{private:intsize;inttop;DataElem*elem;public:Stack(intsize);voidPush(DataEleme);voidPop(D
5、ataElem&e);boolEmpty();intTopPtr();int&operator[](inti){assert(i<=top);returnelem[i];}};intStack::TopPtr(){returntop;}Stack::Stack(intsize){elem=newDataElem[size];this->size=size;top=-1;}voidStack::Pop(DataElem&e){assert(top!=-1);e=elem[top--];}voidStack::Push(DataEleme){assert(top!=size-1);ele
6、m[++top]=e;}boolStack::Empty(){returntop==-1;}voidprint(Stack&s,DataElem*w){for(inti=0;i<=s.TopPtr();i++)cout<0&&k=0){s.Push(k);T-=w[k];}k++;}if(T==0)print(s,w);s.Pop(k);T+=w[k];k++;}while(!s.Emp
7、ty()
8、
9、k!=n);}voidmain(){DataElemw[]={1,2,3,4,5,6,7,8,9,10};knapsack(w,10/*背包大小,必须保证此值不小于数组w的元素中的最大值*/,sizeof(w)/sizeof(DataElem));}/*趣味题计算N!,要求打印出每一位*/#include#include#include47C++程序设计习题解答(王挺)usingna
此文档下载收益归作者所有