1 条题解

  • 0
    @ 2021-6-15 13:05:30

    C++ :

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int main()
    {
    	int p[9]={1,2,3,4,5,6,7,8,9};
    	do
    	{
    		if((p[0]<p[2])&&(p[0]*10+p[1])*(p[2]*10+p[3])==(p[4]*10+p[5])*(p[6]*100+p[7]*10+p[8]))
    			cout<<p[0]<<p[1]<<" x "<<p[2]<<p[3]<<" = "<<p[4]<<p[5]<<" x "<<p[6]<<p[7]<<p[8]<<endl;
    	}
    	while(next_permutation(p,p+9));
    	return 0;
    }
    
    

    Pascal :

    var i,i1,i2,i3,i4,i5,i6,i7,i8,s1,s2,s3,s4:longint;
    begin
      for i:=1 to 7 do
        if i<>3 then
        for i1:=1 to 9 do
          if i1<>i then
            for i2:=1 to 9 do
              if (i2<>i1) and (i2<>i) then
                for i3:=1 to 9 do
                  if (i3<>i2) and (i3<>i1)and(i3<>i) then
                     for i4:=1 to 9 do
                       if (i4<>i3) and (i4<>i2) and (i4<>i1) and (i4<>i) then
                         for i5:=1 to 9 do
                           if (i5<>i4) and (i5<>i3) and (i5<>i2) and (i5<>i1) and (i5<>i) then
                             for i6:=1 to 9 do
                               if (i6<>i5)and (i6<>i4) and (i6<>i3) and (i6<>i2) and (i6<>i1) and (i6<>i) then
                                 for i7:=1 to 9 do
                                   if (i7<>i6)and (i7<>i5)and (i7<>i4) and (i7<>i3)and(i7<>i2)and(i7<>i1)and(i7<>i) then
                                     for i8:=1 to 9 do
                                       if (i8<>i7) and (i8<>i6)and(i8<>i5)and(i8<>i4)and(i8<>i3)and(i8<>i2)and(i8<>i1)and(i8<>i) then
                                       begin
                                         s1:=i*10+i1;
                                         s2:=i2*10+i3;
                                         s3:=i4*10+i5;
                                         s4:=i6*100+i7*10+i8;
                                         if (s1*s2=s3*s4)  then
                                           if (s1>59)and(s2<59) then
                                           else
                                             if (s1>69)and(s2<69) then
                                             else
                                             writeln(s1,' x ',s2,' = ',s3,' x ',s4);
                                       end;
    end.
    
    • 1

    信息

    ID
    812
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者