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

  1. main()
  2. {
  3.     int *left, *right, *doub;
  4.     int l,m, i=0,j,k;
  5.     int nd=0;
  6.     char *malloc();
  7. left=(int *)malloc(500*sizeof(int));
  8. right=(int *)malloc(500*sizeof(int));
  9. doub=(int *)malloc(500*sizeof(int));
  10.  
  11.     for(i=0;i<500;i++)doub[i]=0;
  12.     i=0;
  13.     while( scanf("%d%d",&j,&k)==2)
  14.     if(j>=0 && k>=0){left[i]=j; right[i]=k; i++;}
  15.     else break;
  16.     i--;
  17.     for (j=0;j<=i;j++)
  18.     {
  19.         k=left[j];
  20.         for(m=0;m<=i;m++)if(k==right[m]){doub[nd++]=k;break;}
  21.     }
  22.     if(nd){
  23. /*        for(i=0;i<nd;i++)if(doub[i])printf("%d\n",doub[i]);*/
  24.  
  25.         if(nd>=2){
  26.             for(i=0;i<nd-1;i++)
  27.             for(j=i+1;j<nd;j++)
  28.             if(doub[i]>doub[j]){k=doub[i];doub[i]=doub[j];doub[j]=k;}
  29.             else {}
  30.         }else printf("%d\n",doub[0]);
  31.  
  32.     }else{}
  33.     doub[nd]= -1;
  34. /*        for(i=0;i<nd;i++)if(doub[i])
  35. printf("%d\n",doub[i]);
  36. */
  37.  
  38. k= -1;
  39.  
  40.     for(i=0;i<nd;i++)if(doub[i]!=doub[i+1])
  41. printf("%d\n",doub[i]);
  42.  
  43.     return 0;
  44. }
  45.