一个好玩的算法
1111000111000111111111111
0101011110100011110001111
这样的两个串如何求同样位置都是1的总数?
[解决办法]
经调试!
procedure TForm1.Button1Click(Sender: TObject);
var
s1,s2: string;
i,count: Integer;
begin
s1 := '1111000111000111111111111 ';
s2 := '0101011110100011110001111 ';
count := 0;
for I := 1 to Length(s1) do
if (StrToInt(s1[I]) and StrToInt(s2[I]))= 1 then Inc(Count);
ShowMessage( '同样位置都是1的总数: '+IntToStr(Count));
end;