//模拟穷举法
using System;
class jiema
{
public enum mimaji : int
{
jin = 0,
shu0 = 48,
shu1,
shu2,
shu3,
shu4,
shu5,
shu6,
shu7,
shu8,
shu9,
a = 97,
b = 98,
c = 99,
d = 100,
e = 101,
f = 102,
g = 103,
h = 104,
i = 105,
j = 106,
k = 107,
l = 108,
m = 109,
n = 110,
o = 111,
p = 112,
q = 113,
r = 114,
s = 115,
t = 116,
u = 117,
v = 118,
w = 119,
x = 120,
y = 122,
z = 123,
}
public mimaji[] a;
public int n;
public string mima;
public string jieguo = "";
public DateTime kaishi;
public DateTime jieshu;
public long jilu = 0;
public jiema(string m, int Ln)
{
kaishi = DateTime.Now;
n = Ln;
mima = m;
if(n == 0)
{
n = 10;
}
a = new mimaji[n];
for(int j = 1; j < n; j++)
{
a[j] = mimaji.jin;
}
a[0] = 0;
}
private void Next(int i)
{
switch( a[i] )
{
case mimaji.jin :
a[i] = mimaji.shu0;
break;
case mimaji.shu0 :
a[i] = mimaji.shu1;
break;
case mimaji.shu1 :
a[i] = mimaji.shu2;
break;
case mimaji.shu2 :
a[i] = mimaji.shu3;
break;
case mimaji.shu3 :
a[i] = mimaji.shu4;
break;
case mimaji.shu4 :
a[i] = mimaji.shu5;
break;
case mimaji.shu5 :
a[i] = mimaji.shu6;
break;
case mimaji.shu6 :
a[i] = mimaji.shu7;
break;
case mimaji.shu7 :
a[i] = mimaji.shu8;
break;
case mimaji.shu8 :
a[i] = mimaji.shu9;
break;
case mimaji.a :
a[i] = mimaji.b;
break;
case mimaji.b :
a[i] = mimaji.c;
break;
case mimaji.c :
a[i] = mimaji.d;
break;
case mimaji.d :
a[i] = mimaji.e;
break;
case mimaji.e :
a[i] = mimaji.f;
break;
case mimaji.f :
a[i] = mimaji.g;
break;
case mimaji.g :
a[i] = mimaji.h;
break;
case mimaji.h :
a[i] = mimaji.i;
break;
case mimaji.i :
a[i] = mimaji.j;
break;
case mimaji.j :
a[i] = mimaji.k;
break;
case mimaji.k :
a[i] = mimaji.l;
break;
case mimaji.l :
a[i] = mimaji.m;
break;
case mimaji.m :
a[i] = mimaji.n;
break;
case mimaji.n :
a[i] = mimaji.o;
break;
case mimaji.o :
a[i] = mimaji.p;
break;
case mimaji.p :
a[i] = mimaji.q;
break;
case mimaji.q :
a[i] = mimaji.r;
break;
case mimaji.r :
a[i] = mimaji.s;
break;
case mimaji.s :
a[i] = mimaji.t;
break;
case mimaji.t :
a[i] = mimaji.u;
break;
case mimaji.u :
a[i] = mimaji.v;
break;
case mimaji.v :
a[i] = mimaji.w;
break;
case mimaji.w :
a[i] = mimaji.x;
break;
case mimaji.x :
a[i] = mimaji.y;
break;
case mimaji.y :
a[i] = mimaji.z;
break;
default :
a[i] = mimaji.shu0;
if( i < ( n - 1 ) )
{
Next( i + 1 );
}
break;
}
}
public bool yanzheng()
{
int i = 0;
bool zhaodao = false;
do
{
jieguo = "";
for( int j = 0; j < n; j++)
{
if( a[j] != mimaji.jin )
{
jieguo += (char)a[j];
}
else
{
break;
}
}
jilu++;
Console.WriteLine("正在验证密码:{0}", jieguo);
if( jieguo == mima )
{
zhaodao = true;
break;
}
Next(0);
if( jilu % 37 == 0 )
{
i++;
}
}
while( i < 10 );
jieshu = DateTime.Now;
return zhaodao;
}
}
class Test
{
static void Main()
{
string mima;
int Ln;
do
{
Console.WriteLine("请输入密码(密码不能超过10位):");
mima = Console.ReadLine();
}while( (mima.Length > 10 ) && ( mima.Length <= 0 ) );
do
{
Console.WriteLine("请输入密码可能的最大长多:(密码最大长度不能大于10)");
Ln = int.Parse( Console.ReadLine() );
}while( ( Ln > 10 ) && ( Ln <= 0 ) );
Console.WriteLine("================================================================================");
jiema app = new jiema(mima, Ln);
Console.WriteLine("================================================================================");
Console.WriteLine("开始时间:{0}", app.kaishi);
Console.WriteLine("结束时间:{0}", app.jieshu);
Console.WriteLine("耗时:{0}", app.jieshu - app.kaishi);
Console.WriteLine("验证{0}个密码。", app.jilu);
bool jieguo = app.yanzheng();
if(jieguo)
{
Console.WriteLine("正确密码:{0}");
}
else
{
Console.WriteLine("未找到正确密码。");
}
}
}
请问这个C#程序哪错了?