摘要: // 一个模拟发牌的程序。#include <stdio.h>#include <stdlib.h>#include <time.h>#define NUM_SUITS 4#define NUM_RANKS 13#define TRUE 1#define FALSE 0typedef int Bool;main(){ Bool in_hand[NUM_SUITS][NUM_RANKS] = {0}; int num_cards, rank, suit; const char rank_code[] = {'2', '3', & 阅读全文
posted @ 2013-04-23 23:59 He_LiangLiang 阅读(415) 评论(1) 推荐(0) 编辑
摘要: 几个 Simple 的递归例子 1 #include <iostream> 2 using namespace std; 3 4 // 递归求 n! 5 int fact(int n) 6 { 7 if (n <= 1) 8 return 1; 9 else10 return n * fact(n-1);11 };12 13 // 递归求 x^n (x的n次方)14 int power(int x, int n)15 {16 if (0 == n)17 return 1;18 else19 ret... 阅读全文
posted @ 2013-04-23 23:49 He_LiangLiang 阅读(256) 评论(0) 推荐(0) 编辑
摘要: 面试必考。。。。。 1 #include <stdio.h> 2 class CBase 3 { 4 public: 5 virtual void f(int x) 6 { 7 printf("CBase::f 函数打印:整数%d\n",x); 8 } 9 10 void g(float x)11 {12 printf("CBase::g 函数打印:浮点小数%f\n",x);13 }14 };15 16 // 继承类 CDerived17 class CDerived:public CBase18 {19 publ... 阅读全文
posted @ 2013-04-23 23:36 He_LiangLiang 阅读(526) 评论(0) 推荐(0) 编辑
摘要: 快速排序算法(quicksort) 递归经常作为【分治法(divide-and-conquer)】技术的结果自然地出现。这种称为分治法的算法设计技术把一个大问题划分成多个较小的问题,然后采用相同的算法分别解决这些小问题。分治法的经典示例就是流行的排序算法----快速排序(quicksort)。快速排序算法的操作如下(为了简化,假设要排序的数组的下标从1到n) 1.选择数组元素e(作为“分割元素”),然后重新排列数组使得元素从1一直到i-1都是小于或等于元素e的,元素i包含e,而元素从i+1一直到n都是大于或等于e的。 2.通过递归地采用快速排序方法,对从1到i-1的元素进行排序。 3.通... 阅读全文
posted @ 2013-04-23 23:18 He_LiangLiang 阅读(632) 评论(0) 推荐(0) 编辑
摘要: 规律题1:根据以下数字规律,判断最后一个数字是?13 17 29 52 82 ( )【分析】1+3=4, 13+4=17; // 13可以拆为 1, 31+7=8, 17+4+8=29;2+9=11, 29+4+8+11=52;5+2=7, 52+4+8+11+7=82;8+2=10, 82+4+8+11+7+10=122规律题2:根据以下数字规律,判断()中的答案是ABCD中的哪一个?6 4 8 9 12 9 () 26 30 A.12 B.16 C.18 D.22【分析】首尾相对两项相加可组成等差数列, 36, 30, 24, 18, 12.规律题3:根据以下数字... 阅读全文
posted @ 2013-04-23 12:01 He_LiangLiang 阅读(747) 评论(0) 推荐(0) 编辑