随笔分类 -  C++算法设计

摘要:#include #include #include "TestFunction.h"#include using namespace std;//using ::testing::InitGoogleTest;using namespace testing;#pragma comment(lib, "gtestd.lib")void main(int argc, char **argv){ /*cout > total; SeekScore(total); int wait; cin >> wait;*/ //GTEST_FLAG(o 阅读全文
posted @ 2013-07-06 12:40 Predator 阅读(495) 评论(0) 推荐(0)
摘要:#include using namespace std;class TTest{public: void (TTest::*pfun)(void); void test(); void fun(void);};void TTest::fun(){ cout *pfun)(); }int main(){ TTest* t=new TTest(); t->fun(); t->test(); delete t; int wait; cin >> wait; return 0;} 阅读全文
posted @ 2013-07-06 12:39 Predator 阅读(162) 评论(0) 推荐(0)
摘要:#include #include using namespace boost;using namespace std;void main(){ boost::shared_ptr p = boost::make_shared(14); cout other = p; cout > wait;} 阅读全文
posted @ 2013-07-06 12:37 Predator 阅读(997) 评论(0) 推荐(0)
摘要:#include#include #include #include using namespace boost;using namespace std;void main(){ srand(time(0)); int tem; for (int i = 0; i > wait;}#include#include #include #include int RandBetween(int a, int b) { int result; result = a + rand() % ( b - a + 1); return result;}using namespace boost;usin 阅读全文
posted @ 2013-07-06 12:34 Predator 阅读(226) 评论(0) 推荐(0)
摘要://题目要求一辆卡车违反交通规则,撞人后逃跑。//现场有三人目击事件,但都没有记住车号,只记下车号的一些特征。//甲说:“车牌的前两位数字相同。”//乙说:“车牌的后两位数字是相同的,但与前两位不同。”//丙说:“四位的车号刚好是一个整数的平方。”请推理出车号。“#includeusingnamespacestd;voidmain(){ intn; intm; for(inti=1000;i>wait; return;} 阅读全文
posted @ 2013-07-03 18:07 Predator 阅读(482) 评论(0) 推荐(0)
摘要://题目要求n(n>= 3)个评委打分,去掉最高分和最低分,剩余n-2个得分的平均值为选手得分//具体的算法如下://一下两种算法性能的比较//当n = 100000,第一种方法耗时0.001秒,第二种方法为18.114秒,两种方法的结果都是49999.5 //当n = 1000000,第一种方法耗时0.008秒结果都是500000,第二种方法无法知道,因为第二种方法的运行次数为1000000 * 1000000 = 10000亿次,本人的电脑配置,不知需等待多久,可能需要巨型机吧,可见算法优化很重要//第一种方法:#include#include#include using names 阅读全文
posted @ 2013-07-03 18:06 Predator 阅读(1811) 评论(0) 推荐(0)
摘要:#include using namespace std;void main(){int n; //求的十进制数cout > n;int saveData[1000]; //保存转换后的的位数;int count = 0; //统计转换后有多少位数int radix =0 ; //转换的基数比如2表示二进制,8表示8进制...cout > radix;int x; for (int i =0; n; ++i){x = n % radix;n = n / radix;saveData[i] = x;++count;}cout = 0; --j){cout > wait;} 阅读全文
posted @ 2013-07-03 18:05 Predator 阅读(1075) 评论(0) 推荐(0)
摘要:#include #include #include #include #include #include #include #include #include #include #include "CSHOW.H"using namespace boost;using namespace std;extern int num;int main(){string command ; while(true){command.empty();cout " ;char ch;while( 0x0A != (ch =getchar()) ){command.insert( 阅读全文
posted @ 2013-07-01 21:08 Predator 阅读(270) 评论(0) 推荐(0)
摘要:#include #includeusing namespace std;// 方法指针的格式为:int (*ptr)(char *p) 即:返回值(指针名)(参数列表)typedef int (*CallBackFun)(char *p); // 为回调函数命名,类型命名为 CallBackFun,参数为char *p// 方法 Afun,格式符合 CallBackFun 的格式,因此可以看作是一个 CallBackFun int Afun(char *p){ printf("Afun 回调打印出字符%s!\n", p); return 0 ;}// 方法 Bfun,格式 阅读全文
posted @ 2013-07-01 21:07 Predator 阅读(867) 评论(0) 推荐(0)
摘要:timer tm;date dtStartDate = from_undelimited_string("20080116"); date dtEndDate = from_undelimited_string("20130120"); date tem ;int count = 0;int gap = 0;if (dtStartDate > dtEndDate) {return ;}if (dtStartDate.day_of_week() == 0){tem = dtStartDate;}else{gap = dtStartDate.day_o 阅读全文
posted @ 2013-06-28 21:21 Predator 阅读(580) 评论(0) 推荐(0)
摘要:#include#includeusingnamespacestd; //声明超大数类classBigNum{private: char*pszNnum; intlength;public: BigNum(); BigNum(constchar*); BigNum(constBigNum&bigNum); virtual~BigNum(); intDisplay(); BigNumoperator+(BigNum); BigNum&operator=(BigNum);}; BigNum&BigNum::operator=(BigNumbigNum){ this-> 阅读全文
posted @ 2013-06-25 15:53 Predator 阅读(631) 评论(0) 推荐(0)
摘要:#includeusing namespace std;void scopy1(char s[],char ct[]){int i=0;while (ct[i]!='\0'){s[i]=ct[i];i++;}s[i]='\0';}void scopy2(char *s, char *ct){while(*ct != '\0'){*s=*ct;s=s+1;ct=ct+1;}*s = '\0';}void scopy3(char *s, char *ct){while(*ct) *s++=*ct++;*s = '\0' 阅读全文
posted @ 2013-06-25 13:10 Predator 阅读(661) 评论(0) 推荐(0)
摘要:#include#includeusingnamespaceboost;usingnamespacestd; voidStrCpy(charszDestination[],charszSource[]){ inti=0; while(szSource[i]!='\0'){ szDestination[i]=szSource[i]; i++; } szDestination[i]='\0';}intmain(){ charszDes[10]; charszSource[20]="C++程序设计";//strcpy(szDes,szSource) 阅读全文
posted @ 2013-06-25 13:09 Predator 阅读(289) 评论(0) 推荐(0)
摘要:#includeusingnamespacestd;voidStrCpy(char**pDestination,char*pSource);voidmain(){ char*pString=NULL; StrCpy(&pString,"ganquanfu"); cout>tem;} voidStrCpy(char**pDestination,char*pSource){ char*pResult; inti=0; intlen=0; while(pSource[i]!='\0') { i++; len++; } *pDestination=ne 阅读全文
posted @ 2013-06-24 19:43 Predator 阅读(226) 评论(0) 推荐(0)
摘要:#includeusingnamespacestd;voidStrCpy(char**pDestination,char*pSource);structPeople{ People() { nAge=0; } intnAge; };voidmain(){ char*pString; StrCpy(&pString,"fsfsafsadfsadfsadfsadfsdfsadfsadf"); cout>tem; } voidStrCpy(char**pDestination,char*pSource){ //cout=0) { **pDestination=pSo 阅读全文
posted @ 2013-06-24 19:13 Predator 阅读(480) 评论(0) 推荐(0)
摘要:#includeusingnamespacestd;voidStrCpy(charpDestination[],char*pSource); voidmain(){ charpString[40]; StrCpy(pString,"ganquanfu2008"); cout>tem;} voidStrCpy(charpDestination[],char*pSource){ inti=0; intlen=0; while(pSource[i]!='\0') { i++; len++; } intj=len-1; while(j>=0) { pDe 阅读全文
posted @ 2013-06-24 09:39 Predator 阅读(245) 评论(0) 推荐(0)
摘要:#include <iostream> #include <boost/date_time.hpp>using namespace std;using namespace boost::gregorian;//返回dtLastDatetime相对于dtCurDatetime日期的第几周int GetOrderWeek(const date &dtLastDatetime, const date &dtCurDatetime);void main(){int order = 100;order += 200;date myCurDatetime = fro 阅读全文
posted @ 2013-06-22 09:31 Predator 阅读(1280) 评论(0) 推荐(0)