资源简介
本书从写代码的规范性、完整性、鲁棒性方面,全面展示一道简单面试题,需要考虑的因素,是基于测试编程面试指南的范本,值得推荐…………
《剑指Offer——名企面试官精讲典型编程题》附带的源代码,内含解决50余道编程面试题的完整源代码(含单元测试代码)。打开InterviewQuestions.sln需要Visual Studio 2008或者更新的版本。项目名称前面的数字和《剑指Offer——名企面试官精讲典型编程题》中面试题的编号对应。
将该书的源代码上传到这里,希望对大家有用…………
代码片段和文件信息
// 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“);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2011-10-24 11:38 InterviewQuestions\Accumulate\
文件 3414 2011-09-30 15:25 InterviewQuestions\Accumulate\Accumulate.cpp
文件 4528 2011-06-08 17:26 InterviewQuestions\Accumulate\Accumulate.vcproj
文件 1417 2011-10-24 11:50 InterviewQuestions\Accumulate\Accumulate.vcproj.HAIHE-WIN7.Harry He.user
文件 1320 2011-04-19 07:36 InterviewQuestions\Accumulate\ReadMe.txt
文件 297 2011-04-19 07:36 InterviewQuestions\Accumulate\stdafx.cpp
文件 320 2011-04-19 07:36 InterviewQuestions\Accumulate\stdafx.h
文件 765 2011-04-19 07:36 InterviewQuestions\Accumulate\targetver.h
目录 0 2011-10-24 11:38 InterviewQuestions\AddTwoNumbers\
文件 932 2011-09-30 15:25 InterviewQuestions\AddTwoNumbers\AddTwoNumbers.cpp
文件 4537 2011-06-08 17:26 InterviewQuestions\AddTwoNumbers\AddTwoNumbers.vcproj
文件 1417 2011-10-24 11:50 InterviewQuestions\AddTwoNumbers\AddTwoNumbers.vcproj.HAIHE-WIN7.Harry He.user
文件 1338 2011-04-18 16:07 InterviewQuestions\AddTwoNumbers\ReadMe.txt
文件 300 2011-04-18 16:07 InterviewQuestions\AddTwoNumbers\stdafx.cpp
文件 320 2011-04-18 16:07 InterviewQuestions\AddTwoNumbers\stdafx.h
文件 765 2011-04-18 16:07 InterviewQuestions\AddTwoNumbers\targetver.h
目录 0 2011-10-24 11:38 InterviewQuestions\AssignmentOperator\
文件 2455 2011-09-30 15:25 InterviewQuestions\AssignmentOperator\AssignmentOperator.cpp
文件 4552 2011-06-08 17:40 InterviewQuestions\AssignmentOperator\AssignmentOperator.vcproj
文件 1417 2011-10-24 11:50 InterviewQuestions\AssignmentOperator\AssignmentOperator.vcproj.HAIHE-WIN7.Harry He.user
文件 1368 2011-06-08 17:31 InterviewQuestions\AssignmentOperator\ReadMe.txt
文件 305 2011-06-08 17:31 InterviewQuestions\AssignmentOperator\stdafx.cpp
文件 320 2011-06-08 17:31 InterviewQuestions\AssignmentOperator\stdafx.h
文件 765 2011-06-08 17:31 InterviewQuestions\AssignmentOperator\targetver.h
目录 0 2011-10-24 11:38 InterviewQuestions\BalancedBinaryTree\
文件 6081 2011-09-30 15:25 InterviewQuestions\BalancedBinaryTree\BalancedBinaryTree.cpp
文件 4554 2011-06-08 17:26 InterviewQuestions\BalancedBinaryTree\BalancedBinaryTree.vcproj
文件 1417 2011-10-24 11:50 InterviewQuestions\BalancedBinaryTree\BalancedBinaryTree.vcproj.HAIHE-WIN7.Harry He.user
文件 1368 2011-05-27 11:17 InterviewQuestions\BalancedBinaryTree\ReadMe.txt
文件 305 2011-05-27 11:17 InterviewQuestions\BalancedBinaryTree\stdafx.cpp
文件 320 2011-05-27 11:17 InterviewQuestions\BalancedBinaryTree\stdafx.h
............此处省略419个文件信息
- 上一篇:51单片机光敏电阻寻光程序
- 下一篇:myeclipse可视化图形界面插件+安装说明
相关资源
- 高通射频IC面试题目
- 63个HR面试题的几个回答技巧几乎包含
- 华为中兴的FPGA岗位面试题
- SAP FICO 常用面试题目
- 上海菱众信息技术有限公司面试题
- 海信最新一面面经英语面试题
- 华为技术,综合面试问题集
- 江苏鸿信笔试面试题
- 大厂算法面试题库中高频出现的30道典
- 深信服-技术服务面试题及答案.doc
- 安全运维面试题.docx
- 射频面试题精选题目总结.pdf
- 史上最全 69 道 Spring 面试题和答案
- 北京理工大学自动化学院历年考研复
- unity3d最全面试题
- 百度web前端笔试面试题目
- Spring的面试题和答案
- 电子科技大学2011年研究生信号与系统
- 2019年 腾讯面试试题 内部资料
- spring面试题,spring MVC面试题,spring
- 面试题目集锦--二叉树
- C笔试面试题及答案解析(一)
- zw_百度web前端笔试面试题目.zip
- 数据仓库、商业智能相关面试题(带
- 一线互联网企业面试题.pdf
- 算法面试题集锦.pdf
- 今日头条2020年面试题目分享.docx
- 软件测试面试题集锦30题
- Vue.js面试题及答案大全已经帮助大部
- 硬件工程师面试题库
评论
共有 条评论