摘要: /*“水仙花数”是指一个三位数,其各位数的立方和等于该。 例如:153=1的立方+5的立方+3的立方 编写程序:输出所有“水仙花数“ 思路:1、取一个三位数,取百位,十位,个位。 2、分别算出他们的立方和。 4、比较 */ #include #include using namespace std; int main() { int num; int bw,sw,gw... 阅读全文
posted @ 2010-10-27 01:08 瓜蛋 阅读(174) 评论(0) 推荐(0) 编辑
摘要: /*针对职工工资的发放,给出各种标额最少的张数的付款方案, 票额包括:100元、50元、20元、10元、5元、2元、和1元。 思路:1、设工资数为total 2、100元的张数为total/100 50元的张数为total%100/50 20元的张数为total%100%50/20 10元的张数为total%100%50%20/10 5元 ... 阅读全文
posted @ 2010-10-27 01:07 瓜蛋 阅读(237) 评论(0) 推荐(0) 编辑
摘要: /*编写程序,用随机数函数产生1000个1-6之间的随机数。用这1000个随机数分别代表骰子6个面的面值, 要求:输出6个面的面值各自出现的次数。 思路: */ #include #include using namespace std; int main() { int num; int a[6]={0,0,0,0,0,0}; for(int i=0;i<=1000;i++) {... 阅读全文
posted @ 2010-10-27 01:07 瓜蛋 阅读(220) 评论(0) 推荐(0) 编辑
摘要: /*例如:有两个线性表LA=(1,5,7,15) LB=(3,6,8,9,13,15,17) 则: LC=(1,3,6,8,9,13,15,15,17) 上述问题要求可知,LC中的数据元素或是LA中的数据元素,或是LB中的数据元素,则首先设LC为空表,然后将LA或LBs中的元素逐个插入到LC当中。 为使LC中元素按值非递减排列... 阅读全文
posted @ 2010-10-27 01:06 瓜蛋 阅读(626) 评论(0) 推荐(0) 编辑
摘要: 此刻,我想好多人已经放弃了,但是我不会的,看见了一句话,挺好。真的,立刻就把这句话放到了我的博客的标题下面。有些人说,我一直在幻想中生活,在幻想中学习。其实我没有,我也不会,我的经历告诉我,坚持就是胜利。我想我会克服一切困难,达到我的目标 阅读全文
posted @ 2010-10-27 01:06 瓜蛋 阅读(115) 评论(0) 推荐(0) 编辑
摘要: /*编写一个递归函数完成以下公式的运算*/ //sum(n)=1-1/2+1/3-1/4......(其中n>0) #include using namespace std; //非递归算法 float FUN(int n) { int m=1,temp=1; float total=0.0; while(m!=n+1) { total=total+1.0/m*temp; //注... 阅读全文
posted @ 2010-10-27 01:05 瓜蛋 阅读(177) 评论(0) 推荐(0) 编辑
摘要: /*不交换中间变量交换两个数*/ #include using namespace std; void Fun(int&x,int&y) { x=x+y; y=x-y; x=x-y; } int main() { int a=3,b=4; cout<<"交换前"<<endl<<"a="<<a<<"\t"<<"b="<<b<<endl; Fun(a,b); cout<<"交换后&quo 阅读全文
posted @ 2010-10-27 01:05 瓜蛋 阅读(162) 评论(0) 推荐(0) 编辑
摘要: /*找出LA中多余的重复结点生成一个新的表LB。如有线性表LA=(2,3,4,3,5,6,7,4,8,9)存在多余重复结点则: LB=(2,3,4,5,6,7,8,9) */ template class shanchu::void PURGE(T LA) { int i=1,k,x,y; /* 每次循环使当第i个结点不重复的结点*/ while (i<length(LA)) { x... 阅读全文
posted @ 2010-10-27 01:04 瓜蛋 阅读(208) 评论(0) 推荐(0) 编辑
摘要: //main.cpp /************************************************************************/ /* 输入两个数,求最大公约数 思路:手工用笔在纸上求两个数的最大公约数,理清思路,写出循环。 /***********************... 阅读全文
posted @ 2010-10-27 01:03 瓜蛋 阅读(168) 评论(0) 推荐(0) 编辑
摘要: //写一个在一个字符串(n)中寻找一个子串(m)第一个位置的函数。 /*思路: */ #include #include using namespace std; int Find(string str_long,string str_short) { if(str_long.length()>str_l; string str_s; cout>str_s; cout<<Find(s... 阅读全文
posted @ 2010-10-27 01:03 瓜蛋 阅读(2568) 评论(0) 推荐(0) 编辑