一道Delphi程序题,求运行结果(急~~~~~~~)
functionStrToInt(S:string):integer;beginVal(S,Result,Result);end;functionGetAscii(str...
function StrToInt(S: string): integer;
begin
Val(S, Result, Result);
end;
function GetAscii(str:string):LongWord;
var
i:integer;
ii:longword;
begin
ii:=0;
for i:= 1 to length(str) do
ii:=ii+ ord(str[i]);
Result:=ii;
end;
function CalculateCode(SerialNumber, MachineCode: string): string;
//const
// CHART : String = 'ADGE0Z0123U974';
var
i:integer;
ii:longWord;
str,Reg:string;
begin
ii:=0;
ii:=(GetAscii(SerialNumber)-3) * (GetAscii(MachineCode)-1);
str:= inttostr(ii); //计算结果转化为字符串
for i:=1 to Length(str) do
begin
case strtoint(str[i]) of //取字符串第i位转换成数字,
1: Reg:= Reg+ 'A';
2: Reg:= Reg+ 'D';
3: Reg:= Reg+ 'G';
4: Reg:= Reg+ 'E';
5: Reg:= Reg+ '0';
6: Reg:= Reg+ 'Z';
7: Reg:= Reg+ '0';
8: Reg:= Reg+ '1';
9: Reg:= Reg+ '2';
0: Reg:= Reg+ '3'
else Reg:= Reg+ '4';
end;
end;
Result:=Reg;
end;
输入为 5LS8MF64 展开
begin
Val(S, Result, Result);
end;
function GetAscii(str:string):LongWord;
var
i:integer;
ii:longword;
begin
ii:=0;
for i:= 1 to length(str) do
ii:=ii+ ord(str[i]);
Result:=ii;
end;
function CalculateCode(SerialNumber, MachineCode: string): string;
//const
// CHART : String = 'ADGE0Z0123U974';
var
i:integer;
ii:longWord;
str,Reg:string;
begin
ii:=0;
ii:=(GetAscii(SerialNumber)-3) * (GetAscii(MachineCode)-1);
str:= inttostr(ii); //计算结果转化为字符串
for i:=1 to Length(str) do
begin
case strtoint(str[i]) of //取字符串第i位转换成数字,
1: Reg:= Reg+ 'A';
2: Reg:= Reg+ 'D';
3: Reg:= Reg+ 'G';
4: Reg:= Reg+ 'E';
5: Reg:= Reg+ '0';
6: Reg:= Reg+ 'Z';
7: Reg:= Reg+ '0';
8: Reg:= Reg+ '1';
9: Reg:= Reg+ '2';
0: Reg:= Reg+ '3'
else Reg:= Reg+ '4';
end;
end;
Result:=Reg;
end;
输入为 5LS8MF64 展开
2个回答
2009-01-23
展开全部
你可以自己运行测试一下~
procedure TForm1.Button1Click(Sender: TObject);
var
ss:string;
begin
ss:=CalculateCode(Edit1.Text,Edit2.Text);
ShowMessage(ss);
end;
要传入的参数应该是两个啊,你的5LS8MF64是不是分成两个“5LS8”和“MF64”
如果是的话,那结果就是“ZZ013”
如果是“5LS8MF64”和空的话,那结果就是“ED2E2ZZ001”
procedure TForm1.Button1Click(Sender: TObject);
var
ss:string;
begin
ss:=CalculateCode(Edit1.Text,Edit2.Text);
ShowMessage(ss);
end;
要传入的参数应该是两个啊,你的5LS8MF64是不是分成两个“5LS8”和“MF64”
如果是的话,那结果就是“ZZ013”
如果是“5LS8MF64”和空的话,那结果就是“ED2E2ZZ001”
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询