| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 794 人关注过本帖
标题:[求助]模拟穷举法
只看楼主 加入收藏
曲昌文
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2007-5-22
收藏
 问题点数:0 回复次数:2 
[求助]模拟穷举法

//模拟穷举法
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#程序哪错了?

搜索更多相关主题的帖子: 模拟 
2007-09-13 20:52
swc
Rank: 3Rank: 3
等 级:论坛游民
威 望:6
帖 子:394
专家分:83
注 册:2006-4-7
收藏
得分:0 
你的问题太有个性了.

实践、学习、再实践、再学习......
2007-09-14 10:54
曲昌文
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2007-5-22
收藏
得分:0 

什么意思?怎么了?


http://blog..cn/bfgl我的博客
2007-09-14 14:52
快速回复:[求助]模拟穷举法
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016628 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved