用控制台应用程序编写验证码

T13yiyong 2008-12-15 12:18:22
vs2003 用控制台程序编写一个8位验证码, 前面四位是数字 ,后面四位是 字母. 升序 和降序 谢了.....


给 100 分
...全文
147 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljhcy99 2008-12-15
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
//提示
Console.WriteLine("Input string whose length is 8");

//输入
String s = Console.ReadLine();
//判断长度
if (s.Length != 8)
{
Console.WriteLine("Input length should be 8");
s = string.Empty;
s = Console.ReadLine();
}
//判断前四位是数字
try
{
long num = Convert.ToInt64(s.Substring(0, 4));
}
catch (Exception ex)
{
Console.WriteLine("the privious four caracters should be number");
s = string.Empty;
s = Console.ReadLine();

}
//数字升序
string sdata =s.Substring(0, 4);
for (int i = 0; i < s.Substring(0, 4).Length; i++)
{
if(i+1<=s.Substring(0, 4).Length-1)
{
if (sdata[i] > (sdata[i + 1]))
{
Console.WriteLine("the number should be in increasing order");
s = string.Empty;
s = Console.ReadLine();
}
}
}
//判断后四位字母
string ss = s.Substring(4,4);
for (int i = 0; i < ss.Length; i++)
{
if (!char.IsLetter(ss[i]))
{
Console.WriteLine("the last four caracters should be char");
s = string.Empty;
s = Console.ReadLine();
}

}
// 字母升序
for (int i = 0; i < ss.Length; i++)
{
if (i + 1 <= s.Substring(4, 4).Length - 1)
{
if (Convert.ToInt32((char)ss[i]) > Convert.ToInt32((char)ss[i + 1]))
{
Console.WriteLine("the last four caracters should be increasing order");
s = string.Empty;
s = Console.ReadLine();
}
}

}

}
}
}
angelzqchen 2008-12-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ljhcy99 的回复:]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Input string whose length is 8");
String s = Console.ReadLine();
if (s.Length != 8)
{
Console.WriteLine("Inp…
[/Quote]
学习啦
ljhcy99 2008-12-15
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Input string whose length is 8");
String s = Console.ReadLine();
if (s.Length != 8)
{
Console.WriteLine("Input length should be 8");
s = string.Empty;
s = Console.ReadLine();
}
try
{
long num = Convert.ToInt64(s.Substring(0, 4));
Console.WriteLine(s.Substring(0, 4));
}
catch (Exception ex)
{
Console.WriteLine("the privious four caracters should be number");
s = string.Empty;
s = Console.ReadLine();

}
string ss = s.Substring(4,4);
for (int i = 0; i < ss.Length; i++)
{
if (!char.IsLetter(ss[i]))
{
Console.WriteLine("the last four caracters should be char");
s = string.Empty;
s = Console.ReadLine();
}

}

}
}
}
anncesky 2008-12-15
  • 打赏
  • 举报
回复
console编写验证码???????

那用的还不是只是怎么随机啊。。。。晕

web,win的验证都是用Gdi+,去看看吧
bjwtufv 2008-12-15
  • 打赏
  • 举报
回复
顶下
ljhcy99 2008-12-15
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
//提示
Console.WriteLine("Input string whose length is 8");

//输入
String s = Console.ReadLine();
//判断长度
if (s.Length != 8)
{
Console.WriteLine("Input length should be 8");
s = string.Empty;
s = Console.ReadLine();
}
//判断前四位数字
try
{
long num = Convert.ToInt64(s.Substring(0, 4));

}
catch (Exception ex)
{
Console.WriteLine("the privious four caracters should be number");
s = string.Empty;
s = Console.ReadLine();

}
//判断后四位字母
string ss = s.Substring(4, 4);
for (int i = 0; i < ss.Length; i++)
{
if (!char.IsLetter(ss[i]))
{
Console.WriteLine("the last four caracters should be char");
s = string.Empty;
s = Console.ReadLine();
}

}
//判断前四位数字的顺序
string sdata =s.Substring(0, 4);
int Order = 0;
for (int i = 0; i < s.Substring(0, 4).Length; i++)
{
if(i+1<=s.Substring(0, 4).Length-1)
{
if (sdata[i] > (sdata[i + 1]))
{
Order = Order + 1;
}

}
}
//数字为降序
if (Order == 3)
{
Console.WriteLine("the number is in decreasing Order");
}
else
{
Order = 0;
for (int i = 0; i < s.Substring(0, 4).Length; i++)
{
if (i + 1 <= s.Substring(0, 4).Length - 1)
{
if (sdata[i] < (sdata[i + 1]))
{
Order = Order + 1;
}

}
}
////数字为升序
if (Order == 3)
{
Console.WriteLine("the number is in increasing Order");
}
////数字顺序不规则
else
{
Console.WriteLine("the Order for number is not regular");

}
}


//字母顺序
Order = 0;
for (int i = 0; i < s.Substring(4, 4).Length; i++)
{
if (i + 1 <= s.Substring(4, 4).Length - 1)
{
if (Convert.ToInt32((char)ss[i]) > Convert.ToInt32((char)ss[i+1]))
{
Order = Order + 1;
}

}
}
// ////字母降序
if (Order == 3)
{
Console.WriteLine("the character is in decreasing Order");
}
else
{
Order = 0;
for (int i = 0; i < s.Substring(4, 4).Length; i++)
{
if (i + 1 <= s.Substring(4, 4).Length - 1)
{
if (Convert.ToInt32((char)ss[i]) < Convert.ToInt32((char)ss[i + 1]))
{
Order = Order + 1;
}

}
}
//////字母升序
if (Order == 3)
{
Console.WriteLine("the character is in increasing Order");
}
////字母顺序不规则
else
{
Console.WriteLine("the Order for character is not regular");
}
}





}
}
}

62,269

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧