ABCDE全排列

来源:互联网 发布:vpn怎么修改域名 编辑:程序博客网 时间:2024/06/06 01:00

#include "stdafx.h"
#include "string.h"
#include "iostream"
#include "stack"
#include "Windows.h"

using namespace std;

char *str = "12345";
const int     STR_LEN = strlen(str);

int _tmain(int argc, _TCHAR* argv[])
{
    int   counter = 0;
    int   index1,index2,index3,index4, index5;
   
    DWORD    dwStart = GetTickCount() ;
    DWORD    dwEnd;


    for(index1 = 0;  index1 <STR_LEN; index1++)
    {       
        for(index2 = 0; index2<STR_LEN; index2++)
        {
            if(index2 != index1)
            {               
                for(index3 = 0; index3 < STR_LEN; index3++)
                {
                    if((index3!= index1) &&( index3 != index2))
                    {                  
                        for(index4 = 0; index4 < STR_LEN; index4++)
                        {
                            if((index4!= index1) &&( index4 != index2) && (index4!=index3))
                            {
                                for(index5 = 0; index5 < STR_LEN; index5++)
                                {
                                    if((index5 != index1)&&(index5!= index2)&&(index5!= index3)&&(index5!= index4))
                                    {
                                        printf("%c%c%c%c%c \n",str[index1],str[index2],str[index3],str[index4],str[index5]);              
                                        counter++;
                                    }                              
                                }
                             }
                         }                
                    }           
                }       
            }
        }
    }
    
    dwEnd  = GetTickCount();
    printf("ticks = %d\n",dwEnd -dwStart);
    printf("%d**********",counter);

    return 0;
}

原创粉丝点击