摘要: 在C语言中,多个表达式可以用逗号分开,其中用逗号分开的表达式的值分别结算,但整个表达式的值是最后一个表达式的值。   假设b=2,c=7,d=5,   a1=(++b,c--,d+3);   a2=++b,c--,d+3;在C语言中,多个表达式可以用逗号分开,其中用逗号分开的表达式的值分别结算,但整个表达式的值是最后一个表达式的值。   假设b=2,c=7,d=5,   a1=(++b,c--,d... 阅读全文
posted @ 2010-10-27 12:59 瓜蛋 阅读(208) 评论(3) 推荐(0)
摘要: struct Test { Test( int ) {} Test() {} void fun() {} }; void main( void ) { Test a(1); a.fun(); Test b(); b.fun(); } 解答:b.fun(); //b不是Test的实例对象类是结构体的扩展,在类中封装了对数据成员的操作,缺省的成员为私有的,而结构体为公有的,这就... 阅读全文
posted @ 2010-10-27 12:49 瓜蛋 阅读(243) 评论(0) 推荐(0)
摘要: #include <iostream>using namespace std;void UpperCase( char str[] ) // 将 str 中的小写字母转换成大写字母{ for( int i=0; i<sizeof(str)/sizeof(str[0]); ++i ) if( 'a'<=str[i] && str[i]<='z' ) st... 阅读全文
posted @ 2010-10-27 11:49 瓜蛋 阅读(363) 评论(0) 推荐(0)
摘要: 以前的博客是csdn的 http://blog.csdn.net/xtayaitak 阅读全文
posted @ 2010-10-27 01:17 瓜蛋 阅读(191) 评论(0) 推荐(0)
摘要: /* 789 - seven hundred and eighty nine */ /*思路:这人题思路很简单但是用c++程序实现起来比较繁琐,看了答案才知道 可以把 switch(){case}可以改成数组。哎。效率就是不行呀~! 如 char *a[]={"","one","two".........}*/ #include #include using namespace std;... 阅读全文
posted @ 2010-10-27 01:13 瓜蛋 阅读(290) 评论(0) 推荐(0)
摘要: /*输入一个自然数,将该自然数的每一位数字反序输出,例如:输入 12345,输出54321*/ #include using namespace std; /* int main() { cout>ch; cout=0;i--) { cout>num; do { digit=num%10; num=num/10; cout0); return 0; ... 阅读全文
posted @ 2010-10-27 01:12 瓜蛋 阅读(1078) 评论(0) 推荐(0)
摘要: 难点:怎么把行标i 和每行显示的数据的个数联系起来,怎么找出i和j的关系? */ #include using namespace std; int main() { int i,j; for(i=1;i0;j--) cout=1;i--) { for(j=(4-i)*2;j>0;j--) cout<<" "; for(j=1;j<=2*i-1;j++) ... 阅读全文
posted @ 2010-10-27 01:11 瓜蛋 阅读(215) 评论(0) 推荐(0)
摘要: /*直角三角形三条边满足勾股定律。编写程序,找出三角边长度小于50的所有三角形。*/ /*思路:设三边为a b c 玫举所有小于50的三角形。先测试能不能三角形。然后再测试勾股定律。*/ /*注意:直角三角形三边长3 4 5和4 3 5是同一个三角形。*/ #include using namespace std; int main() { int a,b,c,i=0; int cou... 阅读全文
posted @ 2010-10-27 01:11 瓜蛋 阅读(566) 评论(0) 推荐(0)
摘要: /*判断是否为回文数 例如:18981 思路:数字当成字符串数组,数组的下标访问每个元素判断是否为回文数。*/ #include using namespace std; int main() { char ch[30]; cout>ch; cout=len-1) cout<<"是回文数"<<endl; else cout<<"不是回文数"<<endl; /*if... 阅读全文
posted @ 2010-10-27 01:10 瓜蛋 阅读(320) 评论(0) 推荐(0)
摘要: /* 1 空格4次 数字1次 2 2 空格3次 数字2次 3 3 3 空格2次 数字3次 4 4 4 4 5 5 5 5 5 */ #include using namespace std; int const N=5; int main() { for(int i=1;i<=N;i++) { for(int j=1;j<=N-i... 阅读全文
posted @ 2010-10-27 01:10 瓜蛋 阅读(193) 评论(0) 推荐(0)
摘要: /*输出以下图案 * cout using namespace std; int main() { for(int i=1;i0;i--) { for(int j=1;j<=7-i;j++) cout<<" "; for(j=1;j<=i;j++) cout<<"* "; cout<<endl; } } 阅读全文
posted @ 2010-10-27 01:10 瓜蛋 阅读(168) 评论(0) 推荐(0)
摘要: /*找出10000以内的同构数 同构数 376*376=141376 思路:1、输入一个数num 先判断是几位数。记住数位length。 2、然后算它(num)的平方, square。 3、取square的后length位的数值temp 4、temp与num相等,则是同构数。 */ #include #include using namespace std; int... 阅读全文
posted @ 2010-10-27 01:09 瓜蛋 阅读(2473) 评论(0) 推荐(0)
摘要: http://topic.csdn.net/u/20101002/08/1106d03a-dfef-499d-aad9-5d85af21fecb.html?72693 阅读全文
posted @ 2010-10-27 01:08 瓜蛋 阅读(114) 评论(0) 推荐(0)
摘要: /*“水仙花数”是指一个三位数,其各位数的立方和等于该。 例如: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 瓜蛋 阅读(188) 评论(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 瓜蛋 阅读(249) 评论(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 瓜蛋 阅读(233) 评论(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 瓜蛋 阅读(653) 评论(0) 推荐(0)
摘要: 此刻,我想好多人已经放弃了,但是我不会的,看见了一句话,挺好。真的,立刻就把这句话放到了我的博客的标题下面。有些人说,我一直在幻想中生活,在幻想中学习。其实我没有,我也不会,我的经历告诉我,坚持就是胜利。我想我会克服一切困难,达到我的目标 阅读全文
posted @ 2010-10-27 01:06 瓜蛋 阅读(118) 评论(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 瓜蛋 阅读(185) 评论(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 瓜蛋 阅读(166) 评论(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 瓜蛋 阅读(213) 评论(0) 推荐(0)
摘要: //main.cpp /************************************************************************/ /* 输入两个数,求最大公约数 思路:手工用笔在纸上求两个数的最大公约数,理清思路,写出循环。 /***********************... 阅读全文
posted @ 2010-10-27 01:03 瓜蛋 阅读(174) 评论(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 瓜蛋 阅读(2579) 评论(0) 推荐(0)
摘要: 抄了半天数的代码,编译怎么也不能成功,编译成功了,链接错误,链接正确了,确无法运行。。不知道是什么原因。! 阅读全文
posted @ 2010-10-27 01:02 瓜蛋 阅读(87) 评论(0) 推荐(0)
摘要: /*编写一个函数Strlen(char *s)求s字符串的长度并进行测试。*/ #include using namespace std; int Strlen(char *str) { int len=0; while(*(str+len)!='\0') { len++; } return len; } int main() { cout<<"zhang的字符个数为"<<St... 阅读全文
posted @ 2010-10-27 01:02 瓜蛋 阅读(263) 评论(0) 推荐(0)
摘要: 友元(friend)  问题的提出  我们已知道类具有封装和信息隐藏的特性。只有类的成员函数才能访问类的私有成员,程序中的其他函数是无法访问私有成员的。非成员函数可以访问类中的公有成员,但是如果将数据成员都定义为公有的,这又破坏了隐藏的特性。另外,应该看到在某些情况下,特别是在对某些成员函数多次调用时,由于参数传递,类型检查和安全性检查等都需要时间开销,而影响程序的运行效率。  为了解决上述问题,... 阅读全文
posted @ 2010-10-27 01:01 瓜蛋 阅读(192) 评论(0) 推荐(0)
摘要: /*定义一个分数类,分子分母各为私有成员, 规则:默认构造函数分数为1 分子分母要以最简形式存放。如3/9=1/3 定义成员Add,Sub,Mul和Div计算结果仍以最简形式存放 以浮点形式打印分数 思路:问题1.如何对分数约分。分子分母各除以他们的最大公约数 问题2.加减乘除运算 加:通分后加结果再约分 减:通分后减结果再约分 ... 阅读全文
posted @ 2010-10-27 01:00 瓜蛋 阅读(1746) 评论(0) 推荐(0)
摘要: 最近买了本数据结构c++版,刚刚看到线性表就看不下去了,原因是这个c++的数据结构喜欢用模板,这个东东是我最怕的东西,以前学习一本书从来没有这次这么失落过,看来这次是真的要考验我的时候了。我一般学习东西都寻求在最短的时间学会一个东西,可是这次看样子这种思想要打消了,看来要稳扎稳打了。坚持~~ 阅读全文
posted @ 2010-10-27 01:00 瓜蛋 阅读(243) 评论(0) 推荐(0)
摘要: #include #include using namespace std; int main() { ifstream fin("d:\\data\\english_story.txt"); if(fin.good()) { cout<<"打开文件成功,以下是文件内容"<<endl; char ch; while (!fin.eof())//未到文件尾时循环 { ... 阅读全文
posted @ 2010-10-27 00:59 瓜蛋 阅读(200) 评论(0) 推荐(0)
摘要: /* C++奋斗乐园|C++论坛|算法论坛|ACM/ICPC论坛 82 81 80 79 78 77 76 75 74 73 83 50 49 48 47 46 45 44 43 72 84 51 26 ... 阅读全文
posted @ 2010-10-27 00:58 瓜蛋 阅读(257) 评论(0) 推荐(0)
摘要: 唉,今天又为一件小事吵架了,我是极不情愿吵架的。就只为一句话,那么一句话,我就错了。。。 可是谁又能知道我的苦中,老子的苦中,谁能体谅一下。 唉,这人事情我也不知道怎么处理。 看来以后要坚持我的观点了,再这样子下去,会把你惯坏的。 话要说回来了,我瓶什么养你,就为你说的那句二年后的话。呵呵。 事过境迁,二年之后,真的不知道你是什么样子的,也不知道我是样子的。 心里面一直想着怎么样发展我的事业,有个... 阅读全文
posted @ 2010-10-27 00:57 瓜蛋 阅读(122) 评论(0) 推荐(0)
摘要: #include #define SOR(x) (x*x) main() { int a,b=3; a=SOR(b+2); printf("%d",a); } 阅读全文
posted @ 2010-10-27 00:57 瓜蛋 阅读(144) 评论(0) 推荐(0)
摘要: /*通过重载函数调用运算符实现下列数学函数的抽象 f(x,y)=ax*x+by+c */ #include using namespace std; class Fun { public: int operator()(int x,int y)const; }; int Fun::operator()(int x,int y)const { int a,b,c; cin>>... 阅读全文
posted @ 2010-10-27 00:56 瓜蛋 阅读(189) 评论(0) 推荐(0)
摘要: /*please write a program to check three number if can construct a tryaigle*/ #include using namespace std; class CheckTriangle { public: CheckTriangle(int x,int y,int z):a(x),b(y),c(z){} void ope... 阅读全文
posted @ 2010-10-27 00:55 瓜蛋 阅读(743) 评论(0) 推荐(0)
摘要: /* c++在运行期间不会自动检查数组是否越界,设计一个类检查数组是否越界。 */ #include #include using namespace std; class check { public: check(char*s) { str=new char[strlen(s)+1]; strcpy(str,s); len=strlen(s); } char ope... 阅读全文
posted @ 2010-10-27 00:55 瓜蛋 阅读(1722) 评论(0) 推荐(0)
摘要: CC++ 题集(CC++试题和部分答案)1. 以下三条输出语句分别输出什么?[C易] char str1[] = "abc"; char str2[] = "abc"; const char str3[] = "abc"; const char str4[] = "abc"; const char* str5 = "abc"; const char* str6 = "abc"; cout <... 阅读全文
posted @ 2010-10-27 00:54 瓜蛋 阅读(164) 评论(0) 推荐(0)
摘要: #include #include using namespace std; int main() { ifstream in; int a[10]; int j=0; in.open("data.txt",ios_base::in); //你自己要先新建一个num.txt来放数字 while(!in.eof()) { in>>a[j]; cout<<"a["<<j<... 阅读全文
posted @ 2010-10-27 00:54 瓜蛋 阅读(314) 评论(0) 推荐(0)
摘要: #include #include #include using namespace std; typedef multimap::value_type CIT; typedef multimap::const_iterator IT; template void show(IT&it,multimap&r) { for(it=r.begin();it!=r.end();++it) ... 阅读全文
posted @ 2010-10-27 00:52 瓜蛋 阅读(277) 评论(0) 推荐(0)
摘要: #include #include #include #include using namespace std; typedef set::const_iterator CIT; template void show(CIT&it,set&s) { for(it=s.begin();it!=s.end();++it) coutname1; name1.insert(s1,s1+N... 阅读全文
posted @ 2010-10-27 00:51 瓜蛋 阅读(171) 评论(0) 推荐(0)