هذا البرنامج كتبته من مدة طويلة جدا6 سنوات تقريبا , لكن تذكرته ووجدته بين الملفات وهو عبارة عن سطرين لكن أجهدني كثيرا وقت تصميمه !
وهو لإيجاد الإحتمالات الكلية الممكنة بتكرار لمجموع N مثلا 34gfgh6334 ونريد أن نوجد جميع تبديلاتها الممكنة بتكرار في لنقل 4 خانات فقط ,,,
سيقوم البرنامج بتوليد الإحتمالات الممكنة ويعرضها على الشاشة ,, الفكرة أنه يمكن الإستفادة من ال tool في برامج أخرى كبرامج توليد كلمات المرور بعشوائية مثلا !
[color= #007f00;]#include "stdafx.h"
[color= #007f00;]#include <cmath>
[color= #007f00;]#include <iostream>
[color= #0000ff;]using [color= #0000ff;]namespace std;
[color= #0000ff;]int _tmain[color= #000000;]([color= #0000ff;]int argc, _TCHAR[color= #000000;]* argv[color= #000000;][[color= #000000;]][color= #000000;])
[color= #000000;]{
[color= #0000ff;]const [color= #0000ff;]int PLACES[color= #000000;]=[color= #ff0000;]5; [color= #007f00;]//How many places do you want the characters to be placed in, "any number"
[color= #0000ff;]int result[color= #000000;][PLACES[color= #000000;]];
[color= #0000ff;]unsigned [color= #0000ff;]int POW;
[color= #0000ff;]const [color= #0000ff;]int char_num[color= #000000;]=[color= #ff0000;]3; [color= #007f00;]//Define the number of characters
[color= #0000ff;]char STRING[color= #000000;][char_num[color= #000000;]][color= #000000;]=[color= #000000;]{[color= #A31515;]'1',[color= #A31515;]'2',[color= #A31515;]'3'[color= #000000;]}; [color= #007f00;]//Write down your characters array
cout[color= #000000;]<<[color= #A31515;]"The total number of substrings is : "[color= #000000;]<<pow[color= #000000;]([color= #000000;]([color= #0000ff;]float[color= #000000;])char_num,PLACES[color= #000000;])[color= #000000;]<<endl;
cout[color= #000000;]<<[color= #A31515;]"Press Enter to continue displaying the strings"[color= #000000;]<<endl;
cin.[color= #808000;]get[color= #000000;]([color= #000000;]);
[color= #0000ff;]for[color= #000000;]([color= #0000ff;]int q[color= #000000;]=[color= #ff0000;]0;q[color= #000000;]<pow[color= #000000;]([color= #000000;]([color= #0000ff;]float[color= #000000;])char_num,PLACES[color= #000000;]);q[color= #000000;]++[color= #000000;])
[color= #000000;]{
[color= #0000ff;]for[color= #000000;]([color= #0000ff;]int w[color= #000000;]=[color= #ff0000;]0;w[color= #000000;]<PLACES;w[color= #000000;]++[color= #000000;])
[color= #000000;]{
POW[color= #000000;]=pow[color= #000000;]([color= #000000;]([color= #0000ff;]float[color= #000000;])char_num,w[color= #000000;]);
cout[color= #000000;]<<STRING[color= #000000;][[color= #000000;]([color= #000000;](q[color= #000000;]-[color= #000000;](q[color= #000000;]%POW[color= #000000;])[color= #000000;])[color= #000000;]/POW[color= #000000;])[color= #000000;]%char_num[color= #000000;]];
[color= #000000;]}
cout[color= #000000;]<<endl;
[color= #000000;]}
cout[color= #000000;]<<[color= #A31515;]"FINISH"[color= #000000;]<<endl;
cin.[color= #808000;]ignore[color= #000000;]([color= #000000;]);
cin.[color= #808000;]get[color= #000000;]([color= #000000;]); [color= #007f00;]//Freeze the screen, you can also use ctrl+F5 in VS compilers
[color= #0000ff;]return [color= #ff0000;]0;
[color= #000000;]}// perm.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <cmath>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
const int PLACES=5; //How many places do you want the characters to be placed in, "any number"
int result[PLACES];
unsigned int POW;
const int char_num=3; //Define the number of characters
char STRING[char_num]={'1','2','3'}; //Write down your characters array
cout<<"The total number of substrings is : "<<pow((float)char_num,PLACES)<<endl;
cout<<"Press Enter to continue displaying the strings"<<endl;
cin.get();
for(int q=0;q<pow((float)char_num,PLACES);q++)
{
for(int w=0;w<PLACES;w++)
{
POW=pow((float)char_num,w);
cout<<STRING[((q-(q%POW))/POW)%char_num];
}
cout<<endl;
}
cout<<"FINISH"<<endl;
cin.ignore();
cin.get(); //Freeze the screen, you can also use ctrl+F5 in VS compilers
return 0;
}