
C++
阳光总是那么灿烂
这个作者很懒,什么都没留下…
展开
-
计算牛的数目
母牛的故事Problem Description有一头母牛,它每年年初生一头小母牛。每头小母牛从第四个年头开始,每年年初也生一头小母牛。请编程实现在第n年的时候,共有多少头母牛?Input输入数据由多个测试实例组成,每个测试实例占一行,包括一个整数n(0n=0表示输入数据的结束,不做处理。Output对于每个测试实例,输出在第n年的时候母牛的数量。每个输出占原创 2013-09-26 18:38:38 · 991 阅读 · 0 评论 -
尝试有关对象指针的使用方法,里面有自己加的知识,更深入了解了
#include using namespace std;class Time{public: Time(int,int,int);//声明结构成员函数 int hour; int minute; int sec; void get_time();};Time::Time(int h,int m,int s)//定义结构成员函数{ hour=h;原创 2013-04-22 19:22:23 · 652 阅读 · 0 评论 -
对象数组的使用及this指针(自己改的,虽然只是一小点,但是还是有成就感)
#include using namespace std;class Box{public: Box(int h=10,int w=12,int len=15):height(h),width(w),length(len){}//声明有默认参数的构造函数,参数初始化表初始化数据成员 int volume();private: int height; int wi原创 2013-04-22 18:54:07 · 799 阅读 · 0 评论 -
我的正整数——数据成员
#include #include using namespace std; class NaturalNumber {private: int n; public: void setValue (int x);//置数据成员n的值,要求判断是否是正整数 int getValue(); //返回私有数据成员n的值 bool isPrime(); //判断数据原创 2013-04-10 19:30:45 · 563 阅读 · 0 评论 -
我的三角形——类
#include #include using namespace std; class Triangle {public: void Setabc(double x, double y, double z);//置三边的值,注意要能成三角形 void Getabc(double*x, double*y, double*z);//取三边的值原创 2013-03-26 19:12:03 · 628 阅读 · 0 评论 -
#include <queue> 的使用
#include #include using namespace std; //这几个头文件必不可少int main(){queue q; //使用前需定义一个queue变量,且定义时已经初始化while(!q.empty()) q.pop(); //重复使用时,用这个初始化q.push(1); //进队列q.pop(); //出队列int v=q.front原创 2013-12-11 09:23:22 · 6410 阅读 · 0 评论 -
贪心算法之装船问题
问题描述:吉祥号货轮最大载重量为M吨,有N件货物供选择装船,每件货物的重量和价值是不同的。设计程序使得总重量不超过M,且装的货物总价值最大。//*************************//* 任务介绍:贪心算法之 *// 装船问题 *//* 作者: 何香 *//* 完成时间:2013.10.18 *//********原创 2013-10-19 11:40:14 · 1706 阅读 · 0 评论 -
一只小蜜蜂
一只小蜜蜂...Problem Description有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行。请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数。其中,蜂房的结构如下所示。Input输入数据的第一行是一个整数N,表示测试实例的个数,然后是N 行数据,每行包含两个整数a和b(0Output对于每个测试实例,请输出蜜蜂从蜂房a爬到蜂房b的可能路线数,每个原创 2013-09-26 18:57:32 · 1062 阅读 · 3 评论 -
计算a^3=b^3+c^3+d^3
Perfect CubesProblem DescriptionFor hundredsof years Fermat's Last Theorem, which stated simply that for n > 2 there exist no integers a, b, c > 1 suchthat a^n = b^n + c^n, has remained elusiv原创 2013-09-26 18:21:01 · 1666 阅读 · 1 评论 -
字符数组与字符串的转换
1:字符数组换为字符串见代码[cpp] view plaincopyprint?#include #include using namespace std; int main(){ char a[10]="aaaabbbba"; string s(&a[0],&a[strlen(a)]转载 2014-08-21 10:44:53 · 645 阅读 · 0 评论 -
C/C++头文件一览
C、传统 C++ #include //设定插入点 #include //字符处理 #include //定义错误码 #include //浮点数处理 #include //文件输入/输出 #include //参数化输入/输出 #include //数据流输入/输出 #include //定义各种数据类型最值常量 #include //定义本地化函数 #i转载 2014-08-21 12:53:55 · 581 阅读 · 0 评论 -
C语言字符串函数例子程序大全 – string相关
关于字符串函数的应用细则,例子程序 – jerny函数名: stpcpy 功 能: 拷贝一个字符串到另一个 用 法: char *stpcpy(char *destin, char *source); 程序例: #include #include int main(void) { char string[10]; char *str1 = "abcde转载 2014-08-21 13:11:48 · 775 阅读 · 0 评论 -
对于C++窗口编译一闪而过的解决方法 (DEV CPP下)
对于C++窗口编译一闪而过的解决方法 首先来看一个简单的程序(编译环境为 DEV C++。): #include int main() { std::cout "我喜欢C++\n"; return 0; } 以上程序在DEV C++软件下编译,会出现窗口一闪而过的问题~~当然,在VC 6.0也会出现,不过VC 6.0 只要 再 按转载 2014-08-13 11:49:25 · 12419 阅读 · 2 评论 -
对象的引用
#include using namespace std;class Time{public: Time(int,int,int); int hour; int minute; int sec;};Time::Time(int h,int m,int s){ hour=h; minute=m; sec=s;}void fun(原创 2013-04-27 18:22:46 · 550 阅读 · 0 评论 -
对象的引用的变形——&t->*t
#include using namespace std;class Time{public: Time(int,int,int); int hour; int minute; int sec;};Time::Time(int h,int m,int s){ hour=h; minute=m; sec=s;}void fun(原创 2013-04-27 18:24:27 · 863 阅读 · 0 评论 -
FatMouse' Trade
FatMouse' TradeTime Limit : 2000/1000ms(Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 6 AcceptedSubmission(s) : 4Font:Times New Roman | Verdana | GeorgiaFont原创 2013-10-19 12:38:12 · 750 阅读 · 0 评论 -
Moving Tables
Moving TablesTime Limit : 2000/1000ms(Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 1 AcceptedSubmission(s) : 1Font:Times New Roman | Verdana | GeorgiaFont Si原创 2013-10-19 12:46:44 · 759 阅读 · 0 评论 -
动态规划之MAX Sum
Max Sum Time Limit : 2000/1000ms (Java/Other) Memory Limit :65536/32768K (Java/Other)Total Submission(s) : 6 Accepted Submission(s) : 0Font:Times New Roman | Verdana | GeorgiaFont Size:← →Pr原创 2013-11-12 20:41:55 · 820 阅读 · 0 评论 -
C语言中取绝对值函数的区分
头文件为 #includeint 型int abs(int x);long 型long labs(int x);浮点数 float doubledouble fabs(double x);原创 2014-07-31 20:49:08 · 3187 阅读 · 0 评论 -
用递归计算C(m,n)
//****************************//程序名:C(m,n).cpp *//作者:hx *//编制时间:2013年9月25日 *//主要功能:计算C(m,n) *//C(m,n)=C(m-1,n)+C(m-1,n-1);*//****************************#inc原创 2013-09-25 21:55:07 · 1463 阅读 · 0 评论 -
A Mathematical Curiosity
Problem DescriptionGiven twointegers n and m, count the number of pairs of integers (a,b) such that 0 <a < b < n and(a^2+b^2 +m)/(ab) is aninteger.This problem contains multiple test cases!原创 2013-09-16 18:04:45 · 585 阅读 · 0 评论 -
Who is lier?
狱警发现一囚室的窗户栅栏被剪断了。该囚室有四个囚犯。 A说:不是我 B说:是C C说:是D D说:C胡说已知三个人说真话,一个人说假话。请找出说谎的人。解析:可能的状况有lier=‘A',lier=’B',lier=‘C',lier=‘D'。枚举是按照这 4 种假定逐一地去测试4个人的话有几个人的话是真话。如果不满足3句话为真,就否定这一个假定。when lier=‘A',代入四原创 2013-09-09 21:16:27 · 1031 阅读 · 1 评论 -
点Point 圆Circle 圆柱Cylinder的继承与派生
#include //using namespace std;class Point{private: double x; double y;public: Point(double x1,double y1) { x=x1; y=y1; } ~Point()//析构函数 { cout<<"The constructor of Point原创 2013-06-17 18:58:19 · 1740 阅读 · 0 评论 -
商品折扣问题
#include using namespace std;class Product{public: Product(int m,int q,float p):num(m),quantity(q),price(p){}; void total(); static float average(); static void display();private: int num;原创 2013-05-07 21:55:35 · 1435 阅读 · 0 评论 -
函数max用指向对象的指针作函数参数
#include using namespace std;class Student{public: Student(int n,int s):num(n),score(s){}; void display(); int num; int score;};void Student::display(){ cout<<num<<":"<<score<<endl;}in原创 2013-05-07 21:52:26 · 1411 阅读 · 0 评论 -
建立一个数组,内存放5个学生的数据(学号、成绩),用指针指向数组首元素,输出1、3、5学生的数据
#include using namespace std;class Student{public: Student(int n,int s):num(n),score(s){}; void display();private: int num; int score;};void Student::display(){ cout<<num<<":"<<score<<en原创 2013-05-07 21:49:01 · 2252 阅读 · 0 评论 -
使用静态成员函数 统计学生成绩
//统计学生平均成绩#include using namespace std;class Student{public: Student(int n,int a,int s):num(n),age(a),score(s){} void total(); static float average();//声明静态成员函数private: int num;原创 2013-04-27 19:03:43 · 3642 阅读 · 0 评论 -
C/C++中的日期和时间
C/C++中的日期和时间[推荐]摘要:本文从介绍基础概念入手,探讨了在C/C++中对日期和时间操作所用到的数据结构和函数,并对计时、时间的获取、时间的计算和显示格式等方面进行了阐述。本文还通过大量的实例向你展示了time.h头文件中声明的各种函数和数据结构的详细使用方法。1.概念通过学习许多C/C++库,你可以有很多操作、使用时间的方法。但在这之前你需要了解一些“时间”和“转载 2015-05-27 10:10:09 · 674 阅读 · 0 评论