摘要: 题目:给定一个长度为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 阅读(1307) 评论(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 阅读(1322) 评论(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 阅读(983) 评论(0) 推荐(1)