您的位置:首页 > 编程语言 > C#

c# 组合字符串组成密码的所有可能

2012-09-19 09:16 239 查看
using System;

using System.Collections.Generic;

using System.Text;

namespace pwd

{

class Program

{

private static char[] sourceChar ={ '1', 'b'};

static void Main(string[] args)

{

List<String> bb = aa(4);

Console.WriteLine(":" + bb.Count);

for (int i = 0; i < bb.Count; i++)

{

Console.WriteLine(bb[i]);

}

Console.Read();

}

private static List<String> aa(int num)

{

int currentNum = 2;

List<String> aa = new List<string>();

int currentSize = 0;

int lastindex = 0;

for (int i = 0; i < sourceChar.Length; i++)

{

aa.Add(sourceChar[i].ToString());//密码数组

}

while (currentNum <= num)//当前位数小于输入位数时,循环

{

currentSize = aa.Count;

for (int j = lastindex; j < currentSize; j++)

{

for (int i = 0; i < sourceChar.Length; i++)

{

aa.Add(aa[j].ToString() + sourceChar[i].ToString());

}

}

lastindex = currentSize;

currentNum++;

}

return aa;

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐