資源簡介
劍指offer完整版PDF帶目錄源碼(C++和Java版)
代碼片段和文件信息
//?Accumulate.cpp?:?Defines?the?entry?point?for?the?console?application.
//
//?《劍指Offer——名企面試官精講典型編程題》代碼
//?著作權所有者:何海濤
#include?“stdafx.h“
//?====================方法一====================
class?Temp
{
public:
????Temp()?{?++?N;?Sum?+=?N;?}
????static?void?Reset()?{?N?=?0;?Sum?=?0;?}
????static?unsigned?int?GetSum()?{?return?Sum;?}
private:
????static?unsigned?int?N;
????static?unsigned?int?Sum;
};
unsigned?int?Temp::N?=?0;
unsigned?int?Temp::Sum?=?0;
unsigned?int?Sum_Solution1(unsigned?int?n)
{
????Temp::Reset();
????Temp?*a?=?new?Temp[n];
????delete?[]a;
????a?=?NULL;
????return?Temp::GetSum();
}
//?====================方法二====================
class?A;
A*?Array[2];
class?A
{
public:
????virtual?unsigned?int?Sum?(unsigned?int?n)?
????{?
????????return?0;?
????}
};
class?B:?public?A
{
public:
????virtual?unsigned?int?Sum?(unsigned?int?n)?
????{?
????????return?Array[!!n]->Sum(n-1)?+?n;?
????}
};
int?Sum_Solution2(int?n)
{
????A?a;
????B?b;
????Array[0]?=?&a;
????Array[1]?=?&b;
????int?value?=?Array[1]->Sum(n);
????return?value;
}
//?====================方法三====================
typedef?unsigned?int?(*fun)(unsigned?int);
unsigned?int?Solution3_Teminator(unsigned?int?n)?
{
????return?0;
}
unsigned?int?Sum_Solution3(unsigned?int?n)
{
????static?fun?f[2]?=?{Solution3_Teminator?Sum_Solution3};?
????return?n?+?f[!!n](n?-?1);
}
//?====================方法四====================
template??struct?Sum_Solution4
{
????enum?Value?{?N?=?Sum_Solution4::N?+?n};
};
template?<>?struct?Sum_Solution4<1>
{
????enum?Value?{?N?=?1};
};
template?<>?struct?Sum_Solution4<0>
{
????enum?Value?{?N?=?0};
};
//?====================測試代碼====================
void?Test(int?n?int?expected)
{
????printf(“Test?for?%d?begins:\n“?n);
????if(Sum_Solution1(n)?==?expected)
????????printf(“Solution1?passed.\n“);
????else
????????printf(“Solution1?failed.\n“);
????if(Sum_Solution2(n)?==?expected)
????????printf(“Solution2?passed.\n“);
????else
????????printf(“Solution2?failed.\n“);
????if(Sum_Solution3(n)?==?expected)
????????printf(“Solution3?passed.\n“);
????else
????????printf(“Solution3?failed.\n“);
}
void?Test1()
{
????const?unsigned?int?number?=?1;
????int?expected?=?1;
????Test(number?expected);
????if(Sum_Solution4::N?==?expected)
????????printf(“Solution4?passed.\n“);
????else
????????printf(“Solution4?failed.\n“);
}
void?Test2()
{
????const?unsigned?int?number?=?5;
????int?expected?=?15;
????Test(number?expected);
????if(Sum_Solution4::N?==?expected)
????????printf(“Solution4?passed.\n“);
????else
????????printf(“Solution4?failed.\n“);
}
void?Test3()
{
????const?unsigned?int?number?=?10;
????int?expected?=?55;
????Test(number?expected);
????if(Sum_Solution4::N?==?expected)
????????printf(“Solution4?passed.\n“);
????else
????????printf(“Solution4?failed.\n“);
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????157184??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\.vs\InterviewQuestions\v14\.suo
?????文件???????3414??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\Accumulate\Accumulate.cpp
?????文件???????4528??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\Accumulate\Accumulate.vcproj
?????文件???????1417??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\Accumulate\Accumulate.vcproj.HAIHE-WIN7.Harry?He.user
?????文件???????5169??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\Accumulate\Accumulate.vcxproj
?????文件???????1321??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\Accumulate\Accumulate.vcxproj.filters
?????文件???????1320??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\Accumulate\ReadMe.txt
?????文件????????297??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\Accumulate\stdafx.cpp
?????文件????????320??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\Accumulate\stdafx.h
?????文件????????765??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\Accumulate\targetver.h
?????文件????????932??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\AddTwoNumbers\AddTwoNumbers.cpp
?????文件???????4537??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\AddTwoNumbers\AddTwoNumbers.vcproj
?????文件???????1417??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\AddTwoNumbers\AddTwoNumbers.vcproj.HAIHE-WIN7.Harry?He.user
?????文件???????5178??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\AddTwoNumbers\AddTwoNumbers.vcxproj
?????文件???????1324??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\AddTwoNumbers\AddTwoNumbers.vcxproj.filters
?????文件???????1338??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\AddTwoNumbers\ReadMe.txt
?????文件????????300??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\AddTwoNumbers\stdafx.cpp
?????文件????????320??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\AddTwoNumbers\stdafx.h
?????文件????????765??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\AddTwoNumbers\targetver.h
?????文件???????2455??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\AssignmentOperator\AssignmentOperator.cpp
?????文件???????4552??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\AssignmentOperator\AssignmentOperator.vcproj
?????文件???????1417??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\AssignmentOperator\AssignmentOperator.vcproj.HAIHE-WIN7.Harry?He.user
?????文件???????5193??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\AssignmentOperator\AssignmentOperator.vcxproj
?????文件???????1329??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\AssignmentOperator\AssignmentOperator.vcxproj.filters
?????文件???????1368??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\AssignmentOperator\ReadMe.txt
?????文件????????305??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\AssignmentOperator\stdafx.cpp
?????文件????????320??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\AssignmentOperator\stdafx.h
?????文件????????765??2017-10-10?21:46??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\AssignmentOperator\targetver.h
?????文件??????58013??2017-10-10?21:47??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\Backup\InterviewQuestions.sln
?????文件?????158208??2017-10-10?21:47??劍指offer完整版帶目錄源碼(C++和Java版)\InterviewQuestions\Backup\InterviewQuestions.v12.suo
............此處省略764個文件信息
- 上一篇:電影售票網站-Java
- 下一篇:ssm人力資源管理系統
評論
共有 條評論