Friday, June 5, 2015

UVa - 725 - Division


  1. /****************#####    بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم  #####*******************
  2. __________________________________________________________________________
  3. ######################  Ya-Seen Arafat(ACWizard) #########################
  4. ######################        UAP-CSE-33B        #########################
  5. *************************************************************************/
  6. #include <bits/stdc++.h>
  7. #define sc(n) scanf("%d", &n)
  8. #define S 10003
  9. using namespace std;
  10. typedef long long LL;
  11.  
  12. int check[10], cn;
  13.  
  14. struct data{
  15.     int first, second;
  16. }arr[S];
  17.  
  18. void check_digit(int NN){
  19.     cn = 0;
  20.     while(NN > 0){
  21.         int mod = NN%10;
  22.         if(!check[mod])cn++, check[mod] = 1;
  23.         NN /= 10;
  24.     }
  25. }
  26.  
  27. int cmp(data a, data b){
  28.     if(a.first == b.first)return a.second < b.second;
  29.     return a.first < b.first;
  30. }
  31.  
  32. void Do(){
  33.     int n, d, bl = 0;
  34.     while(sc(n) == 1){
  35.         if(== 0)break;
  36.         int k = 0;
  37.         memset(arr, 0sizeof(arr));
  38.         for(int i = 98765; i >= 10000; i--){
  39.             memset(check, 0sizeof(check));
  40.             check_digit(i);
  41.             if(cn < 5)continue;
  42.             if(!(i%n)){
  43.                 int N = i/n; cn = 0;
  44.                 d = log10(N)+1;
  45.                 if(>= 4){
  46.                     check_digit(N);
  47.                     if(!check[0] && cn == 4 && d == 4){
  48.                         arr[k].first = i;
  49.                         arr[k++].second = N;
  50.                     }
  51.                     if(cn == 5){
  52.                         arr[k].first = i;
  53.                         arr[k++].second = N;
  54.                     }
  55.                 }
  56.             }
  57.         }
  58.         sort(arr, arr+k, cmp);
  59.         if(bl)puts(""); bl = 1;
  60.         if(!k)printf("There are no solutions for %d.\n", n);
  61.         else{
  62.             for(int i = 0; i < k; i++){
  63.                 int ll = log10(arr[i].second);
  64.                 if(ll == 4)printf("%d / %d = %d\n", arr[i].first, arr[i].second, n);
  65.                 else printf("%d / 0%d = %d\n", arr[i].first, arr[i].second, n);
  66.             }
  67.         }
  68.     }
  69. }
  70.  
  71. int main(){
  72.     ios_base::sync_with_stdio(0); cin.tie(0);
  73.     #ifndef ONLINE_JUDGE
  74.     ///freopen("inp","r",stdout);
  75.     ///freopen("contest.txt","w",stdout);
  76.     #endif
  77.     Do();
  78.     return 0;
  79. }

No comments:

Post a Comment