大神们看看如何修改 (80分)

P1618 三连击(升级版)

wolfball @ 2016-06-02 21:02:01

var
s,s1,s2,s3:string;
j:char;
a,b,c:real;
i,flag:longint;
begin
    readln(a,b,c);
    for i:=123 to 987 do 
    begin
        if (i*b/a>999) or (i*c/a>999) then continue;
        if (trunc(i*b/a)<>i*b/a)or(trunc(i*c/a)<>i*c/a) then continue; 
        str(i,s1);
        str(i*b/a,s2);
        str(i*c/a,s3);
        s:=s1+s2+s3;
        for j:='1' to '9' do
                if pos(j,s)=0 then break;
        if pos(j,s)=0 then continue;
        writeln(i*a:0:0,' ',i*b:0:0,' ',i*c:0:0);inc(flag);
    end;if flag=0 then write('No!!!');
end.

by 姚文涛 @ 2016-06-03 13:06:08

var
a,b,c,x,y,z,i,m,n,j,k,l:longint;//ABC比值,XYZ各个数值
function duan(x,y,z:longint):boolean;
var i1,i2,i3,i4,i5,i6,i7,i8,i9:longint;
begin
duan:=false;         //疯子一样的打表 有一点点的优化 注意没有 0 的存在
i1:=x div 100; i2:=x div 10 mod 10; i3:=x mod 10; 
i4:=y div 100; i5:=y div 10 mod 10; i6:=y mod 10; 
i7:=z div 100; i8:=z div 10 mod 10; i9:=z mod 10;
if (i1 <> 0) and (i2 <> 0) and (i3 <> 0) and (i4 <> 0) and (i5 <> 0) and (i6 <> 0) and (i7 <> 0) and (i8 <> 0) and (i9 <> 0) then
if (i1 <> i2) and (i1 <> i3) and (i1 <> i4) and (i1 <> i5) and (i1 <> i6) and (i1 <> i7) and (i1 <> i8) and (i1 <> i9) then
if (i2 <> i3) and (i2 <> i4) and (i2 <> i5) and (i2 <> i6) and (i2 <> i7) and (i2 <> i8) and (i2 <> i9) then
if (i3 <> i4) and (i3 <> i5) and (i3 <> i6) and (i3 <> i7) and (i3 <> i8) and (i3 <> i9) then
if (i4 <> i5) and (i4 <> i6) and (i4 <> i7) and (i4 <> i8) and (i4 <> i9) then
if (i5 <> i6) and (i5 <> i7) and (i5 <> i8) and (i5 <> i9) then
if (i6 <> i7) and (i6 <> i8) and (i6 <> i9) then
if (i7 <> i8) and (i7 <> i9) and (i8 <> i9) then duan:=true;
//  writeln(x,' ',y,' ',z,' ',duan);
end;
begin
readln(a,b,c);
for i:=100 to 777 do      //最大的是7:8:9 ,所以到777足够了
begin
x:=i; y:=i*b div a; z:=c*i div a;     //算出来各个数值
if z<1000 then  //大于1000的直接舍弃
   if duan(x,y,z) then begin
                       writeln(x,' ',y,' ',z);  
                       inc(k);//计算是否有答案,否则后文输出NO
                       end;
end;
if k=0 then writeln('No!!!'); 
end.

by wolfball @ 2016-06-03 16:01:10

那我的哪里有错误@姚文涛


by Deny_小田 @ 2016-06-03 20:43:26

你打个表就行了,最后一个点的输出是 123 456 789(不确定啊)


|