- 博客(92)
- 收藏
- 关注
转载 八皇后
转载:http://zhedahht.blog.163.com/blog/static/2541117420114331616329 解决这个问题通常需要用递归,而递归对编程能力的要求比较高。因此有不少面试官青睐这个题目,用来考察应聘者的分析复杂问题的能力以及编程的能力。 由于八个皇后的任意两个不能处在同一行,那么肯定是每一个皇后占据一行。于是我们可以定义一个数组colum
2015-12-29 11:37:06
624
原创 二叉搜索树BST
在二叉搜索树b中查找x的过程为:1.若b是空树,则搜索失败,否则:2.若x等于b的根结点的数据域之值,则查找成功;否则3.若x小于b的根结点的数据域之值,则搜索左子树:否则4.查找右子树// 指针parent指向pRoot的父节点,其初始调用值为NULL// 若查找成功,指针pTarget指向目标节点,函数返回true// 否则指针pTarget指向查找路径上访问的最后一个
2015-12-27 22:46:15
616
原创 指向指针的指针和指针的引用
当我们把一个指针作为一个参数传递给函数时,其实是把指针的copy传递给了函数,也可以说传递指针是指针的值传递。如果我们在函数内部修改指针,修改的只是指针的copy而不是指针本身。代码验证如下:#includeusing namespace std;int num1 = 1;void func(int* p){ p = &num1; cout << p << endl;
2015-12-26 11:58:49
799
原创 归并排序
先递归分解序列,再合并有序数列#include #include #include using namespace std;#define random(x) (rand()%x)void merge_array(int nums[], int first, int mid, int last, int temp[]){ int index1 = first, index2
2015-12-23 10:44:22
547
原创 堆排序
#include #include #include using namespace std;#define random(x) (rand()%x)void heap_adjust(vector& nums, int index, int length){ for(int i = 2 * index; i <= length; i *= 2) { int temp =
2015-12-06 23:15:15
638
原创 快速排序
2015.11.30 面试创云传奇#include #include #include using namespace std;#define random(x) (rand()%x)void quick_sort(vector& vec, int left, int right){ if(left < right) { int pivot = vec[left];
2015-12-06 17:30:19
500
原创 单链表快速排序
2015.11.27 面试一点资讯 ,面试官是很nice的校友师兄,无奈基本功太差,跪了!#include using namespace std;#define random(x) (rand()%x)struct ListNode{ int value; ListNode* next;};void create_list(ListNode* head){ Li
2015-11-28 11:26:20
866
1
原创 UVaOJ 127
`Accordian'' Patience You are to simulate the playing of games of ``Accordian'' patience, the rules for which are as follows:Deal cards one by one in a row from left to right, not ov
2014-09-21 10:20:49
821
原创 C程序设计语言(K&R)第四章学习笔记
#include #include #define MAXLINE 100/* rudimentary calculator */int main(){ double sum, atof(char []); char line[MAXLINE]; int getline(char line[], int max); sum = 0; while (getline(line
2014-08-01 20:40:52
811
原创 C程序设计语言(K&R)第一章学习笔记
#include /*print Fahrenheit-Celsius table for fahr=0,20,...,300;floating-point version*/int main(){ float fahr,celsius; float lower,upper,step; lower = 0; /*lower limit of tempera
2014-07-28 20:48:30
1287
原创 算法竞赛入门经典6.2.1
#include #define maxn 50000+10int A[maxn];int find(int A[],int x);void shift_circular_left(int A[],int p,int q);void shift_circular_right(int A[],int q,int p);int main(){ int n,m; int X,Y; i
2014-07-23 15:47:05
781
原创 UVaOJ 10474 大理石在哪?
Where is the Marble? Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on them. At the beginning, Raju would place the marbles one after anoth
2014-07-18 10:37:03
780
原创 UvaOJ 10420 战利品列表
#include #include #include #define maxn 2000+10#define N 75+10char ss[N];char country[maxn][maxn];int cmp(const void *_a,const void *_b);int main(){ int n,i; int len; int total,q=0; scanf
2014-07-17 22:24:10
615
原创 UVaOJ 340 猜数字游戏的提示
#include #define maxn 1000+10using namespace std;int secret[maxn],cp_secret[maxn],guess[maxn];void judge(int secret[],int guess[],int n,int &a,int &b);int main(){ int n,a,b,cnt=1; while(cin>>
2014-07-17 19:38:43
926
原创 UvaOJ 424 整数查询
#include #include #define maxn 100+10#define INF 1e9char str[maxn][maxn];int num[maxn][maxn];int ans[maxn];int main(){ int i=0,j; int count,len,max=-INF,flag; while(~scanf("%s",str[i]))/
2014-07-16 15:14:12
713
原创 UVa OJ 537 人工智能
Physics teachers in high school often think that problems given as text are more demanding than pure computations. After all, the pupils have to read and understand the problem first!So they don't
2014-07-15 20:18:22
1320
原创 UVa OJ 10361 自动作诗机
#include #include int main(){int n,i;char ch[4][100],temp;scanf("%d",&n);getchar();while(n--){for(i=0;imemset(ch[i],0,sizeof(ch[i]));for(i=0;(temp=getchar())!='putcha
2014-07-14 15:40:13
890
原创 UVa OJ 回文词(401)
/*******************************************Problem:UVA OJ-401 PalindromesDate:11/07/2014Author:Praker********************************************/#include #include #define maxn 10000char str
2014-07-12 11:25:44
821
原创 C++如何输入多行字符串(含空格)
#include #include using namespace std;int main(){ string s; int n; cin>>n; for(int i=0;i<n;i++) { cin>>s; cout<<s<<endl; } return 0;}
2014-07-10 18:58:52
48279
1
原创 字母重排
#include #include #include int n;char word[2000][10],sorted[2000][10];//字符比较函数int cmp_char(const void* _a,const void* _b){ char* a=(char*)_a; char* b=(char*)_b; return *a-*b;}//字符串比较函数
2014-07-08 19:48:20
1024
原创 6174问题
#include #include int num[2000],count;int get_next(int x);int main(){ scanf("%d",&num[0]); printf("%d",num[0]); count =1; for(;;) { num[count]=get_next(num[count-1]);//生成并输出下一个数 printf(
2014-07-08 14:52:40
668
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人