procedure TForm1.Button1Click(Sender: TObject);
var
S: String;
i: Integer;
Sum: Integer;
begin
S:= Edit1.Text;
Sum:= 0;
for i:= 1 to Length(S) do
begin
If S in ['0'..'9'] then
Sum:= Sum*10 + StrtoInt(S)+ StrtoInt(S);
end;
Edit2.Text:= Inttostr(sum);
end;
//上述问题是(100+20+3)*2=(((0*10+1)*10+2)*10+3
procedure TForm1.Button2Click(Sender: TObject);
var
S: String;
i: Integer;
Sum: Integer;
begin
S:= Edit2.Text;
Sum:= 0;
for i:= 1 to Length(S) do
begin
If S in ['0'..'9'] then
Sum:= Sum*10 + StrtoInt(S); //三次循环完成后,Sum=246
end;
Sum=Sum div 2;
Edit1.Text:= Inttostr(sum);
end;
//上述问题是(200+40+6)/2=((((0*10+2)*10+4)*10+6) div 2
// Sum:= Sum*10 + StrtoInt(S); //三次循环完成后,Sum=246
//也可改为 Sum:= Sum*10 + StrtoInt(S) div 2; //三次循环完成后,Sum=123
//然后将 Sum=Sum div 2; 删掉