上一页 1 2 3 4 5 6 7 8 9 ··· 12 下一页
摘要: 题目:在一个int数组里查找这样的数,它大于等于左侧所有数,小于等于右侧所有数。答:#include "stdafx.h"#include <iostream>using namespace std;//数组中大于等于左侧所有数,小于等于右侧所有数的数void FindSpecialNumber(int *arr, int length){ if (NULL == arr || length <= 0) { return; } int *rightMin = new int[length]; rightMin[length - 1] = arr[le... 阅读全文
posted @ 2012-09-06 19:47 venow 阅读(1611) 评论(0) 推荐(0) 编辑
摘要: 题目:求最大连续递增数字串(如“ads3sl456789DF3456ld345AA”中的“456789”。答:#include "stdafx.h"#include <iostream>#include <string>using namespace std;//求最大连续递增数字串string FindMaxIncreNumberSeq(string str){ if ("" == str || str.length() <= 0) { return NULL; } int maxlength = 0; int start 阅读全文
posted @ 2012-09-06 19:39 venow 阅读(1829) 评论(0) 推荐(1) 编辑
摘要: 题目:一个长度为n的数组a[0],a[1],...,a[n-1]。现在更新数组的各个元素,即a[0]变为a[1]到a[n-1]的积,a[1]变为a[0]和a[2]到a[n-1]的积,...,a[n-1]为a[0]到a[n-2]的积(就是除掉当前元素,其他所有元素的积)。要求:具有线性复杂度,且不能使用除法运算符。答:#include "stdafx.h"#include <iostream>using namespace std;void PrintArray(int *a, int length){ for (int i = 0; i < length; 阅读全文
posted @ 2012-09-06 19:31 venow 阅读(659) 评论(0) 推荐(0) 编辑
摘要: 题目:求两个串中的第一个最长子串(神州数码以前试题)。如"abractyeyt","dgdsaeactyey"的最大子串为"actyey"。答:#include "stdafx.h"#include <iostream>#include <string>using namespace std;//两个串中的第一个最长子串string FindLongestCommonSubString(string strOne, string strTwo){ if ("" == st 阅读全文
posted @ 2012-09-06 19:24 venow 阅读(1816) 评论(0) 推荐(0) 编辑
摘要: 题目:给定一个长度为N的整数数组,只允许用乘法,不能用乘法,计算任意(N-1)个数的组合乘积中最大的一组,并写出算法的时间复杂度。答:#include "stdafx.h"#include <iostream>using namespace std;#define INFINITY_MAX 32767#define INFINITY_MIN -32767void PrintSubArray(int *arr, int length, int key){ bool first = true; for (int i = 0; i < length; i++) 阅读全文
posted @ 2012-09-05 19:40 venow 阅读(1294) 评论(0) 推荐(1) 编辑
摘要: 题目:如下:int A[nSize],其中隐藏着若干0,其余非0整数,写一个函数int Func(int* A, int nSize),使A把0移至后面,非0整数移至数组前面并保持有序,返回值为原数据中第一个元素为0的下标。(尽可能不使用辅助空间且考虑效率及异常问题,注释规范且给出设计思路)。答:#include "stdafx.h"#include <iostream>using namespace std;int Func(int *A, int nSize){ if (NULL == A || nSize <= 0) { return -1; } i 阅读全文
posted @ 2012-09-05 19:30 venow 阅读(1305) 评论(0) 推荐(0) 编辑
摘要: 题目:将一个随机的整数转换成一个按各位上数值大小排序的整数,例如整数2541转换成1245,随机整数521368转换成123568,要求不能使用一步到位的库函数.答:#include "stdafx.h"#include <iostream>using namespace std;//字符串数字从小到大输出void Solution(char *str){ if (NULL == str) { return; } unsigned int hashTab[10] = {0}; char *p = str; while (*p != '\0') . 阅读全文
posted @ 2012-09-05 19:26 venow 阅读(965) 评论(0) 推荐(1) 编辑
摘要: 题目:对于一颗完全二叉树,要求给所有节点加上一个pNext指针,指向同一层的相邻节点;如果当前节点已经是该层的最后一个节点,则将pNext指针指向NULL;给出程序实现,并分析时间复杂度和空间复杂度。答:时间复杂度为O(n),空间复杂度为O(1)。#include "stdafx.h"#include <iostream>#include <fstream>#include <vector>using namespace std;struct TreeNode { int m_nValue; TreeNode *m_pLeft; Tree 阅读全文
posted @ 2012-09-04 19:36 venow 阅读(1014) 评论(0) 推荐(0) 编辑
摘要: #include "stdafx.h"#include <iostream>using namespace std;#define MAXSIZE 20typedef struct{ int r[MAXSIZE + 1]; int length;}SqList;//***********************************起泡排序*************************************beginvoid BubbleSort(SqList& L){ bool flag = false; for (int i = L.leng 阅读全文
posted @ 2012-09-04 19:27 venow 阅读(462) 评论(0) 推荐(0) 编辑
摘要: 题目:输入两个整数n和m,从数列1,2,3.....n中随意曲几个数,使其和等于m,要求将其中所有的可能组合列出来。答:#include "stdafx.h"#include <iostream>#include<list> using namespace std;//1到N中所有和为M的组合void FindAllCombinationEqualM(list<int> &l, int m, int n){ if (m <= 0 || n <= 0) { return; } if (m == n) { for (lis 阅读全文
posted @ 2012-09-04 19:23 venow 阅读(1109) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 12 下一页