home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / vrac / tpchal_1.zip / RBS.C < prev    next >
C/C++ Source or Header  |  1994-05-22  |  2KB  |  60 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. main()
  6. {
  7.       unsigned posn, avail;
  8.       char *fill[] = {
  9.             "123456789", "12354678", "1253467", "152346",
  10.             "51234", "1234", "123", "12", "1", ""};
  11.       char number[11]
  12. #ifndef TEST
  13.       = "0123456789";
  14. #else
  15.       ;
  16.       int I;
  17.  
  18.       for (I = 0; I < 1000; ++I)
  19.       {
  20.             strcpy(number, " 123456789");
  21. #endif
  22.             for (posn = 1, avail = 0xffff; posn < 10; ++posn)
  23.             {
  24.                   unsigned dig = number[posn] - '0';
  25.                   unsigned long n;
  26.  
  27.                   if (1 != posn)
  28.                   {
  29.                         int i, res;
  30.  
  31.                         n = 10 * n + dig;
  32.                         res = (int)(n % posn);
  33.  
  34.                         if ((0 != res) || (0 == dig) ||
  35.                               (!(avail & (1 << dig))) ||
  36.                               ((dig & 1) != (posn & 1)))
  37.                         {
  38.                               n += posn - res;
  39.                               for (i = posn; i; n /= 10, --i)
  40.                               {
  41.                                     if (number[i] == (dig = n % 10 + '0'))
  42.                                           break;
  43.                                     number[i] = dig;
  44.                               }
  45.                               strcpy(number + posn + 1, fill[posn]);
  46.                               posn = 0;
  47.                               avail = 0xffff;
  48.                               continue; 
  49.                         }
  50.                   }
  51.                   else  n  = dig;
  52.                   avail &= ~(1 << dig);
  53.             }
  54. #ifdef TEST
  55.       }
  56. #endif
  57.       printf("Number = %ld\n", atol(number));
  58.       return 0;
  59.