Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. // Uva -- Division
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. int i,n;
  7. int iTemp; 
  8. int iTemp2;
  9. int iCount;
  10. int iBucket[10];   // store digit 0 ~ 9
  11. bool bRecord;
  12. bool bBlank = 0;
  13. while ( cin >>n )
  14.     {  
  15.     if ( n == 0 )
  16.         break; 
  17.     if ( bBlank == 1 )
  18.         cout <<endl;
  19.     bBlank = 1;
  20.     bRecord = 0;
  21.     iTemp = 1234;
  22.     while ( iTemp*n <= 98765  )
  23.         {  
  24.         iCount = 0;
  25.         for ( i=0 ; i<10 ; i++ )
  26.             iBucket[i] = 0;
  27.         if ( iTemp < 10000 )
  28.             iBucket[0] = 1;
  29.         iTemp2 = iTemp;
  30.         while ( iTemp2 )
  31.             {
  32.             iBucket[iTemp2%10]++;  
  33.             iTemp2 = iTemp2 / 10;  
  34.             }
  35.         iTemp2 = iTemp * n;
  36.         while ( iTemp2 )
  37.             {
  38.             iBucket[iTemp2%10]++;
  39.             iTemp2 = iTemp2 / 10;      
  40.             }      
  41.         for ( i=0 ; i<10 ; i++ )
  42.             if ( iBucket[i] == 1 )
  43.                 iCount++;      
  44.         if ( iCount == 10 )
  45.             {
  46.             cout << iTemp*n << " / ";
  47.             if ( iTemp < 10000 )
  48.                 cout << "0" << iTemp << " = " << n << endl;
  49.             else
  50.                 cout << iTemp << " = " << n << endl;
  51.             bRecord = 1;
  52.             }
  53.         iTemp++;   
  54.         }      
  55.     if ( bRecord == 0 )
  56.         cout << "There are no solutions for " << n << "." <<endl;  
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement