身份證15To18 的算法(C#)

發表于:2007-05-25來源:作者:點擊數: 標簽:算法身份證15To18usingSystem
using System; using System.Threading; namespace KeyboardRecord { /// summary /// Class1 的摘要說明。 /// /summary class Class1 { /// summary /// 應用程序的主入口點。 /// /summary [STAThread] static void Main(string[] args) { // // TODO: 在
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];
}


}
}



原文轉自:http://www.anti-gravitydesign.com

評論列表(網友評論僅供網友表達個人看法,并不表明本站同意其觀點或證實其描述)
国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97