Joseph的问题(c++循环链表)

先看看这个问题怎么来的 据说著名犹太历史学家 Josephus有过以下的故事:在罗马人占领乔塔帕特後,39 个犹太人与Josephus及他的朋友躲到一个洞中,39个犹太人决定宁愿死也不要被人抓到,于是决定了一个自杀方式,41个人排成一个圆圈,由第1个人开始报数,每报数到第3人该人就必须自杀,然后再由下一个重新报数,直到所有人都自杀身亡为止。 然而Josephus 和他的朋友并不想遵从,Josephus要他的朋友先假装遵从,他将朋友与自己安排在第16个与第31个位置,于是逃过了这场死亡游戏。 [不得不说他很机智啊!!!] ...

win32_打砖块游戏开发记录(勤快就更)2016-5-10

///////////////////2016-5-4///////////////////////// 一.游戏名称:打砖块 二.游戏内容描述:任意数量砖块放置在画面顶部,画面底部为一定长度和厚度的条状物,条状物可玩家控制,玩家需要用条状物作为屏幕中一随机小球的降落反弹媒介,确保能使小球再次反弹,并能击中顶部砖块,小球击中砖块,玩家分数对应增加,当玩家击中最后一个砖块后(或小球掉落),视为游戏结束 三.功能与设计: 1.双缓冲页面切换 2.接受键盘输入 3.位图加载(随机位置)与碰撞...

输入两个数,输出两个数之间所有数

#include<iostream> int main() { std::cout<<"Enter two number:"<<std::endl; int v1,v2; std::cin>>v1>>v2; int lower,upper; if(v1<=v2) { lower=v1; upper=v2; } else { lower=v2; upper=v1; } std::cout<<"Values of "<<lower<<"to "<<upper<<"inclusive are:"<<std::endl; ...
c++ | 2014-07-03 20:35 | 阅读 1028 次 | 评论 0 条

this指针应用

#include <iostream> #include <string> using namespace std; class Date { int mo,da,yr; char *month; public: Date(int m=0,int d=0,int y=0); ~Date(); Date&amp; operator=(const Date&amp;); void display() const; }; Date::Date(int m,int d,int y) { static char *mos[]= { "Janua...
c++ | 2014-05-07 19:08 | 阅读 1139 次 | 评论 0 条

NEW and DELETE application

#include<iostream> using namespace std; class CPoint { public: CPoint(int x=0,int y=0); int SetTemp(); void Print(); void Print() const; private: int m_x; const int m_y; static const int m_z; int m_temp; }; void main() { const int ARRAY_SIZE=5; CPoint *pCPoint; pCPoi...
c++ | 2014-05-06 22:02 | 阅读 1013 次 | 评论 0 条

赋值运算符“=”的重载

#include <iostream> #include <string> using namespace std; class Internet { public: Internet(char *name,char *url) { Internet::name=new char[strlen(name)+1]; Internet::url=new char[strlen(url)+1]; if(name) { strcpy(Internet::name,name); } if(url) { strcpy(Int...
c++ | 2014-05-04 21:22 | 阅读 1109 次 | 评论 0 条

虚函数的应用(计算矩形和圆的面积及周长)

class Shape { public: Shape() {} ~Shape() {} virtual float GetArea()=0; virtual float GetPerim()=0; }; class Circle:public Shape { public: Circle(float radius):itsRadius(radius) {} float GetArea() { return 3.14*itsRadius*itsRadius; } float GetPerim() { return ...
c++ | 2014-05-02 23:25 | 阅读 1307 次 | 评论 0 条

继承练习(两个基类派生出一个类)

#include <iostream> using namespace std; typedef char string80 [80]; class Data { public: Data() {} Data(int y, int m, int d) { SetData(y,m,d); } void SetData(int y,int m,int d) { Year=y; Month=m; Day=d; } string80 &amp;GetStringData(string80 &amp;Data) { spr...
c++ | 2014-05-02 22:43 | 阅读 1556 次 | 评论 0 条

DOS界面改变

1.change the DOS title windows+r->cmd->title [what you want] 2.change the DOS prefix windows+r->cmd->prompt [what you want] 3.change the DOS background's color windows+r->cmd->color [bf] (PS:b is representing background's color,you can input the code of...
DOS学习 | 2014-04-27 14:41 | 阅读 1263 次 | 评论 0 条

类和对象综合训练

#include <iostream> using namespace std; class CPoint { public: int x1; int y1; void output(); CPoint();//构造 CPoint(int x2,int y2);//重载 ~CPoint();//析构 private: int x2;; int y2; int *pCount; }; void CPoint::output() { if(pCount) (*pCount)++; else { pCount=new ...
c++ | 2014-04-27 14:09 | 阅读 1313 次 | 评论 0 条

构造函数重载

#include <iostream> using namespace std; class point { private: double fx,fy; public: point();//不带参 point(double fx,double fy);//带参 void showpoint(); }; point::point() { fx=0.0; fy=0.0; } point::point(double x,double y=5.0) { fx=x; fy=y; } void point::showpoint() { ...
c++ | 2014-04-27 09:21 | 阅读 1449 次 | 评论 0 条

定义类的成员函数的实现

#include <iostream> #include <string> using namespace std; class Cbook { private: char *m_pczName; int m_nPages; int m_nEdition; public: void GetBookName(char *pName); int GetTotalPages(); int GetBookEdition(); private: void SetBookName(char *pName); void SetTotalPages(int ...
c++ | 2014-04-26 11:15 | 阅读 1401 次 | 评论 0 条

字符串指针的应用

#include <iostream> #include <string> using namespace std; int main() { char str1[100]="hello"; char *str2="C++"; char *str; int i=0; cout<<"str2="<<str2<<endl; str=strcat(str1,str2); cout<<"strcat(str1,str2)="<<str<<endl; i=strcmp(str1,str2); cout<<"strcmp(str1,str2)="<<i<<...
c++ | 2014-04-19 23:42 | 阅读 1178 次 | 评论 0 条

数组倒序输出

#include <iostream> using namespace std; int main() { int a[5]; int i,j; cout<<"please input five data"<<endl; for(i=0;i<5;i++) cin>>a[i]; cout<<"convert data :"<<endl; for(j=4;j>=0;j--) cout<<a[j]<<"\t"; cout<<endl; return 0; }
c++ | 2014-04-18 22:45 | 阅读 1388 次 | 评论 0 条

圆周长面积计算

#include <iostream> const double PI=3.14; using namespace std; double fcir_l(double r) { double cir_l; cir_l=2*PI*r; return cir_l; } double fcir_s(double r) { double cir_s; cir_s=PI*r*r; return cir_s; } int main() { double radius, cir_l,cir_s; int i...
c++ | 2014-04-16 23:16 | 阅读 1346 次 | 评论 0 条
浏览36895次
最新评论