随笔分类 - C、C++ 刷题
摘要:// 面试题:二进制中1的个数 // 题目:请实现一个函数,输入一个整数,输出该数二进制表示中1的个数。例如 // 把9表示成二进制是1001,有2位是1。因此如果输入9,该函数输出2。 #include using namespace std; //将flag(1)不停左移(右移会出现死循环情况),对每位进行与运算 int NumberOf1_Solution1(int n) { ...
阅读全文
摘要:第三种想法思路: 斐波那契数列扩展:
阅读全文
摘要:// 面试题:旋转数组的最小数字 // 题目:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。 // 输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素。例如数组 // {3, 4, 5, 1, 2}为{1, 2, 3, 4, 5}的一个旋转,该数组的最小值为1。 #include using namespace std; int MinInOrder(int* n...
阅读全文
摘要:// 面试题:用两个栈实现队列 // 题目:用两个栈实现一个队列。队列的声明如下,请实现它的两个函数appendTail // 和deleteHead,分别完成在队列尾部插入结点和在队列头部删除结点的功能。 #include #include using namespace std; template class CQueue//模板类,习惯就好了 { private: sta...
阅读全文
摘要:文件一:main.cpp 文件二:BinaryTree.h 文件三:BinaryTree.cpp
阅读全文
摘要:文件一:main.cpp 文件二:BinaryTree.h 文件三:BinaryTree.cpp
阅读全文
摘要:文件main.cpp 文件List.h 文件List.cpp
阅读全文
摘要:// 替换空格 // 题目:请实现一个函数,把字符串中的每个空格替换成"%20"。例如输入“We are happy.”, // 则输出“We%20are%20happy.”。 #include using namespace std; bool replace_space(char* str,const int length) { if (str == NULL && lengt...
阅读全文
摘要:// 面试题3(二):不修改数组找出重复的数字 // 题目:在一个长度为n+1的数组里的所有数字都在1到n的范围内,所以数组中至 // 少有一个数字是重复的。请找出数组中任意一个重复的数字,但不能修改输入的 // 数组。例如,如果输入长度为8的数组{2, 3, 5, 4, 3, 2, 6, 7},那么对应的 // 输出是重复的数字2或者3。 #include using namespace ...
阅读全文
摘要:// 面试题3(一):找出数组中重复的数字 // 题目:在一个长度为n的数组里的所有数字都在0到n-1的范围内。数组中某些数字是重复的,但不知道有几个数字重复了, // 也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。例如,如果输入长度为7的数组{2, 3, 1, 0, 2, 5, 3}, // 那么对应的输出是重复的数字2或者3。 #include using namespac...
阅读全文
摘要:// 二维数组中的查找 // 题目:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按 // 照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个 // 整数,判断数组中是否含有该整数。 #include using namespace std; bool serach_in(int* matrix, int rows, int cols, int numb...
阅读全文
摘要://重载赋值运算符 #include #include using namespace std; class CMystring { private: char* m_pData;//私有变量m_pData public: CMystring(const char* pData = NULL)//具有默认参数的 含参构造函数,注意此处的const { ...
阅读全文
摘要:#include using namespace std; double HAR_AVG(double, double); void TEST(bool); int main() { double x, y; cout > x; TEST(cin.fail()); cin >> y; TEST(cin.fail()); while (x*y ...
阅读全文
摘要:#include #include using namespace std; int main() { char in_put; do { cout > in_put; if (islower(in_put)) cout using namespace std; const int MAX = 10; ...
阅读全文
摘要:#include using namespace std; int main() { int num_1,num_2,sum=0; cout > num_1; cin >> num_2; if (num_1 > num_2) { int a; a = num_1; num_1 = num_2; ...
阅读全文
摘要:#include #include using namespace std; int main() { string first_name; string last_name; char grade; int age; cout > grade; cout > age; cout #include int main(...
阅读全文
摘要:#include using namespace std; int main() { const int unit=12; int shen_gao; cout > shen_gao; cout using namespace std; const int F_1 = 12; const double F_2 = 0.0254; const double ...
阅读全文
摘要:#include using namespace std; int main() { cout using namespace std; int main() { int a; cout > a; cout void print_1(void); void print_2(void); using namespace std; int main()...
阅读全文

浙公网安备 33010602011771号