摘要: 求和最大的数字组合。findMax(int num[], int n){ int i; int b = 0; int e = 0; int tb = 0; int te = 0; int total = 0; int temp = 0; for(i = 0; i num[i]){ temp = temp + num[i]; te = i; } else{ tb = i; te = i; temp = num[... 阅读全文
posted @ 2014-02-25 19:13 yutoulck 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 在给定数字范围内,求和为某数的全部组合#include struct Zhan{ int n; int content[100];};ruZhan(struct Zhan* zhan, int x){ (*zhan).content[(*zhan).n] = x; (*zhan).n++;}czZhan(struct Zhan* zhan, int n){ (*zhan).n = n;}printfZhan(struct Zhan* zhan){ int i; for(i = 0; i 0){ ruZhan(zhan, e); ... 阅读全文
posted @ 2014-02-25 15:26 yutoulck 阅读(336) 评论(0) 推荐(0) 编辑
摘要: 给定排好序的数字,求和为某数的两个数字组合。#include struct Pair{ int f; int s;} ;int find(int num[], int n, int x, struct Pair pairs[]){ int i = 0; int j = n - 1; int m = 0; for(; i x) j--; else{ pairs[m].f = num[i]; pairs[m].s = num[j]; i++; j--; ... 阅读全文
posted @ 2014-02-25 14:54 yutoulck 阅读(190) 评论(0) 推荐(0) 编辑
摘要: 使用了堆排序,因为没有必要将全部排好序,堆排序恰好符合要求。#include init(int num[], int n){ int h, i; if(n 0){ creatHeap(num, n, h); i--; if((i - 1) / 2 == h) i--; h = (i - 1) / 2;//下一个非叶结点 }}//整理非叶结点的堆creatHeap(int num[], int n, int h){ int temp = num[h];//临时存放数据 int i;//指示叶结点 int... 阅读全文
posted @ 2014-02-25 11:41 yutoulck 阅读(620) 评论(0) 推荐(0) 编辑