我写的小应用程序在二进制系统中绘制数字而没有重复。它适用于2,4,8位,但是当涉及到16个应用程序时,它找不到超过〜7,8k的组合。
以下是代码:
#include <iostream>
#include <vector>
#include <ctime>
#include <cstdlib>
#include <string>
#include <sstream>
#include <conio.h>
#include <math.h>
using namespace std;
string IntToString(int integer)
{
ostringstream ss;
ss<<integer;
string Converted = ss.str();
return Converted;
}
bool IsAlreadyDrawed(string what, vector <string> where)
{
for(int i=0; i<where.size(); i++)
{
if(where[i]==what) return true;
}
return false;
}
vector <string> FillIt(int HowManyBits)
{
vector <string> Randoms;
int random;
string lol;
do
{
for(int i=0; i<HowManyBits; i++) lol+=IntToString((rand()%2));
if(!IsAlreadyDrawed(lol,Randoms))
{
Randoms.push_back(lol);
cout<<"Pushing in "<<lol<<endl;
}
lol.clear();
}
while(Randoms.size()<pow(2,HowManyBits));
return Randoms;
}
void ShowIt(vector <string> What)
{
cout<<"\n";
for(int i=0; i<What.size();i++) cout<<i+1<<". "<<What[i]<<endl;
getch();
}
int main()
{
srand(time(0));
ShowIt(FillIt(16));
}