寻找1995高级程序员下午试题第10题答案
那位能找到1995高级程序员下午试题第10题(pascal设计)的答案,求1个满足下列条件的6位数:
1.该数各数位上的6个数字互不相同
2.该数的2,3,4,5,6倍数,仍然是6位数,他们也符合条件1.
[解决办法]
答案就没有了,但这代码可以这样写:
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
function UniqueStr(x:integer):boolean;
var s,tmp:string;
a:integer;
begin
Result:=true;
s:=inttostr(x);
for a:=1 to 6 do begin
tmp:=s;
delete(tmp,a,1);
if pos(s[a],tmp)>0 then exit;
end;
Result:=false;
end;
function MultipleMaxV(x:integer):boolean;
var b:integer;
begin
Result:=true;
for b:=2 to 6 do
if x*b>999999 then exit;
Result:=false;
end;
begin
for i:=102345 to 987654 do begin
if UniqueStr(i) then continue;
if MultipleMaxV(i) then continue
else begin
showmessage('符合题目要求的数是:"'+inttostr(i)+'"');
exit;
end;
end;
end;