比如给出 2,3,5,7 这四个数字,那么他们的排列组合应该是: 2357
2375
2537
2573
2735
2753
...
...
解决方案 »
- 求加密代码
- treeview相关
- 我装好了delphi,但在做数据库开发的时候找不到Database Desktop这个东西?
- 高分相求:dbgrid 、DRAWGRID、STRINGGRID,中可以插入按钮吗?
- 程序中如何用一個函數來接管消息事件
- 请问Pchar是什么类型 DELPHI6中有ping控件吗?在那个控件组里 叫什么名字?
- 我用ADOQUERY过滤出了部分数据,我现在想在dbgrid中用光标选了一行记录,然后能不能反应出我选的是第几行记录啊?
- 操作foxpro数据库必须配置数据源吗?
- 紧急求救:怎样通过汉字编码获得汉字的声母
- 强烈建议,鼠标一到问题上出现象首页上那样的HInt
- 各位大哥:真的非常非常急,我现在感觉天都要塌下了!
- 结果集排序问题。急...........................
//#include "stdafx.h"#include <vector>
#include <algorithm>using std::cout;
using std::cin;
using std::endl;
using std::vector;template<typename T>
void printList(vector<T> &list) {
for (unsigned int j = 0; j < list.size(); j++) {
cout << list[j];
}
cout << endl;
}template<typename T>
bool contain(vector<T> &list, T value) {
return list.end() != find(list.begin(), list.end(), value);
}template<typename T, unsigned size>
void rank(int floorCount, int curFloor, vector<T> &list, const T (&array)[size]) {
if (list.size() == floorCount) {
printList(list);
} vector<T> curList;
for (int i = curFloor; i < floorCount; i++) {
vector<T>::iterator pos;
for (int j = 0; j < floorCount; j++) {
if (!contain(list, array[j]) && !contain(curList, array[j])) {
list.push_back(array[j]);
curList.push_back(array[j]);
rank(floorCount, curFloor+1, list, array);
list.pop_back();
}
}
}
}template<typename T, unsigned size>
void rank(const T (&array)[size]) {
vector<T> list;
rank(size, 0, list, array);
}int main(int argc, char* argv[])
{
char i[] = {'2', '3', '5', '7', '1'};
rank(i); cin.get();
return 0;
}
这个帖子里面有讨论
http://community.csdn.net/Expert/topic/3887/3887796.xml?temp=.6196405
还有这个也可以参考