正文

身份证15To18 的算法(C#)2009-01-12 16:37:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/yzrj/40460.html

分享到:

using System;using System.Threading; namespace KeyboardRecord{/// <summary>/// Class1 的摘要说明。/// </summary>class Class1{/// <summary>/// 应用程序的主入口点。/// </summary>[STAThread]static void Main(string[] args){//// TODO: 在此处添加代码以启动应用程序//string a = Console.ReadLine();if (a.Length!=15) {Console.WriteLine("Please input correct idnumber");}else{Console.WriteLine(getCheckCode(a));}}static string getCheckCode(string sfzh){char[] strJiaoYan = {''1'', ''0'', ''X'', ''9'', ''8'', ''7'', ''6'', ''5'', ''4'', ''3'', ''2''};int[] intQuan = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1};string strTemp;int intTemp = 0;strTemp = sfzh.Substring(0,6) + "19" + sfzh.Substring(6);for (int i=0;i<=strTemp.Length-1;i++){intTemp += int.Parse(strTemp.Substring(i,1))*intQuan[i];}intTemp = intTemp % 11;return strTemp + strJiaoYan[intTemp];} }}

阅读(939) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册