/*
* Created by SharpDevelop.
* User: Administrator
* Date: 2009-2-21
* Time: 9:30
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
namespace ta
{
class Program
{
static char [] c=new char [8];
public void jym(){
int [] ww={3,7,9,10,5,8,4,2};
int [] cc=new int[8];
int DD=0;
int C9=0;
for(int i=0;i<8;i++){ //将字符转换成ASCILL码
cc[i]=(int)Program.c[i];
if(47<cc[i] && cc[i]<58) cc[i]=cc[i]-48; //将ASCILL码转换成对应数值
else
cc[i]=cc[i]-65;
}
for(int i=0;i<8;i++){
DD+=cc[i]*ww[i];
}
C9=11-DD%11; //计算校验码
if(C9==10){
for(int i=0;i<8;i++)
Console.Write(Program.c[i]); //输出结果
Console.WriteLine("-X");
}
else if(C9==11){
for(int i=0;i<8;i++)
Console.Write(Program.c[i]);
Console.WriteLine("-" + (char)(48));
}
else{
for(int i=0;i<8;i++)
Console.Write(Program.c[i]);
Console.WriteLine("-" + (char)(C9+48));
}
}
static void Main(string[] args){
string ss;
while(true){
Console.WriteLine("请输入长度为8的本体代码:");
ss=Console.ReadLine();
if (ss.Length!=8)
Console.WriteLine("长度不为8,请重新输入!");
else break;
}
for(int i=0;i<ss.Length;i++){
c[i]=Convert.ToChar (ss.Substring(i,1));
}
Program jym=new Program();
jym.jym();
}
}
}