</pre><pre code_snippet_id="619985" snippet_file_name="blog_20150315_2_4545938" name="code" class="cpp">
#include <iostream>
#include <sstream>
#include <fstream>
#include <list>
using namespace std;
void main()
{
unsigned width;//密码位数
unsigned wdtStart, wdtEnd; //输出密码位数区间
list<string> element,pswd, temp, pwdAll; //存放密码字符的容器
list<string>::iterator it, it2, itEle;
element.clear();
pswd.clear();
pwdAll.clear();//存放密码全部
unsigned j = 0; //纯数字密码
stringstream ss;
string s;
string logFile;// = ".\\pswd.txt";
cout << "input save file name" <<endl;
cin >> logFile;
ofstream ostr(logFile.c_str());
cout << logFile <<endl;
cout << "input password min start" <<endl;
cin >> wdtStart;
cout << wdtStart <<endl;
cout << "input password max end" <<endl;
cin >> wdtEnd;
cout << wdtEnd <<endl;
width = wdtEnd;
//初始化密码基本单元
bool produce = true;
while(produce)
{
ss.clear();
ss << j ;
ss >> s;
//cout << "s " << s <<endl;
element.push_back(s);
j++;
if (j > 9)
{
produce = false;
}
}
for (unsigned i = 1; i <= width; i++ )
{
cout << "密码位数: " << i << endl;
temp.clear();
if (i == 1)
{
for (itEle = element.begin(); itEle != element.end(); itEle++)
{
string sEle = (*itEle);
string s = sEle;
pswd.push_back(s);
pwdAll.push_back(s);
if ((wdtStart <= i) && (i <= wdtEnd))
{
ostr << s <<endl;
}
}
}
else
{
for (it = pswd.begin(); it != pswd.end(); it++ )
{
string st = (*it);
cout << "st " << st <<endl;
for (itEle = element.begin(); itEle != element.end(); itEle++)
{
string sEle = (*itEle);
string s = st + sEle;
cout << "s after " << s <<endl;
temp.push_back(s);
pwdAll.push_back(s);
if ((wdtStart <= i) && (i <= wdtEnd))
{
ostr << s <<endl;
}
}
}
pswd.clear();
pswd = temp;
}
}
}