home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume17 / contest-prog / part02 / prob14.c < prev    next >
C/C++ Source or Header  |  1989-02-06  |  1KB  |  57 lines

  1. main(){
  2.     int a[4];
  3.     int numfnd = -1;
  4.     int this, found[10000];
  5.     int t;
  6.     int p,q,r,s,i,j,k,l,n;
  7.     for(i=0;i<10;i++)
  8.         for(j=0;j<10;j++)if(i==j)continue;
  9.         else
  10.             for(k=0;k<10;k++)
  11.                 for(l=0;l<10;l++)if(k==l)continue;
  12.                 else
  13.                 {
  14.                     p=i*10+j;
  15.                     q=k*10+l;
  16.  
  17.                     r=j*10+i;
  18.                     s=l*10+k;
  19.                     if(p==r || p==s ||q==r||q==s)continue;
  20.                     else
  21.                         if((n=p*q) == r*s){
  22.                             int i,j;
  23.                             /*bingo*/
  24.                             a[0]=p;
  25.                             a[1]=q;
  26.                             a[2]=r;
  27.                             a[3]=s;
  28. xxx:
  29.                             for(i=0;i<4;i++)for(j=i;j<4;j++)if(a[i]>a[j]){
  30.                                 t=a[i];
  31.                                 a[i]=a[j];
  32.                                 a[j]=t;
  33.                                 goto xxx;
  34.                             }
  35.                             /*printf("%d %d %d %d %d  " ,p,q,r,s,n);*/
  36.                             this=a[0]*1000000+a[1]*10000+a[2]*100+a[3];
  37.                             if(numfnd== -1){
  38.                                 found[++numfnd]=this;
  39.                                 printf("%d %d\n",a[0],n);
  40.                                 continue;
  41.                             }
  42.                             else{
  43.                                 t=0;
  44.                                 for(i=0;i<=numfnd;i++)if(found[i]==this)t=1;
  45.                             }
  46.                             if(!t)
  47.                             {
  48.                                 found[++numfnd]=this; 
  49.                                 printf("%d %d\n",a[0],n);
  50.                             }
  51.                             else /*putchar('\n')*/ ;
  52.                         }
  53.                 }
  54.  
  55.  
  56. }
  57.