Advertisement
leonardo_aly7

Division uva725

Jan 26th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1. void itoa(int n, char s[]){
  2.     int i = 0 ;
  3.     do {
  4.         s[i++] = n % 10 + '0';
  5.     } while ((n /= 10) > 0);
  6.     s[i] = '\0';
  7. }
  8.  
  9. int main(){
  10.  
  11.  
  12. int n, max=0 ,min = 01234,m=0,i,no = 1;
  13. char c[7];
  14.  
  15. scanf("%d",&n);
  16. while (n){
  17.     if (max)printf("\n");
  18.     m = 0;
  19.     max = 98765;
  20.     min = 01234;
  21.     no = 1;
  22.  
  23.     outer:for(min ; min <= 98765/n ; min++ ){
  24.         m = 0;
  25.         max = min*n;
  26.  
  27.     if (max<10000)continue;
  28.        if (min < 10000)m=1;
  29.  
  30.         itoa(min,c);
  31.         for (i=0;i<5;i++){
  32.  
  33.             if (m&(1<<(c[i]-'0'))){
  34.                 min++;
  35.                 goto outer;
  36.             }
  37.             else m|= 1<<(c[i]-'0');
  38.         }
  39.  
  40.         itoa(max,c);
  41.         for (i=0;i<5;i++){
  42.             if (m &(1<<(c[i]-'0'))){
  43.                 min++;
  44.                 goto outer;
  45.             }
  46.             else m|= 1<<(c[i]-'0');
  47.         }
  48.  
  49.         if (min>9999)
  50.         printf("%d / %d = %d\n",max,min,n);
  51.         else
  52.         printf("%d / 0%d = %d\n",max,min,n);
  53.         no = 0 ;
  54.  
  55.     }
  56.     if (no)
  57.         printf("There are no solutions for %d.\n",n);
  58.     scanf("%d",&n);
  59. }
  60.  
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement