比如给出 2,3,5,7 这四个数字,那么他们的排列组合应该是:     2357
     2375
     2537
     2573
     2735
     2753
     ...
     ...

解决方案 »

  1.   

    现在用的机子上没DELPHI,用C++试着写了个,支持任意长度的// Test.cpp : 定义控制台应用程序的入口点。
    //#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;
    }
      

  2.   

    http://community.csdn.net/Expert/topic/3894/3894741.xml?temp=4.772365E-03
    这个帖子里面有讨论
    http://community.csdn.net/Expert/topic/3887/3887796.xml?temp=.6196405
    还有这个也可以参考