UVA 725 Division

Source: Internet
Author: User

0. Do not use recursion to construct a five-digit number, the direct for loop to the maximum is good, can be slightly pruning a loss, because the minimum number is 01234 from 1234, because the multiplier n is a minimum of 2 and the numerator is a maximum of five digits, so the denominator should be less than 50,000. So the for 1234 to 50000-1 is OK. Oh, there's another reason, fenmu*n>= 100,000 can be thrown away.

1. There's one more thing to repeat .

 while(i) {num[i%Ten]=1; I/=Ten; }     while(j) {Num[j%Ten]=1; J/=Ten; }     for(intI=1;i<Ten; i++) num[0]+=Num[i]; if(num[0]==Ten) {printf ("%d/%05d =%d\n", Fenzi,fenmu,n); OK=true; }

2. Don't forget that when the molecule is less than 10,000, remember that num[0]=1 0 is being used.

3.!!! scanf control format when really really really very useful%nd (n is a number) represents the output%d that number and then less than n bits from the left to start with a space to complement the%0ND represents the output%d that number and then less than n bit from the left to start with 0 complement

1#include <cstdio>2#include <cstring>3 intN;4 BOOLOK;5 intnum[ A];6 voidSolveintIintj)7 {8     intFenmu=i,fenzi=J;9     if(i<10000) num[0]=1;Ten      while(i) One     { Anum[i%Ten]=1; -I/=Ten; -     } the      while(j) -     { -num[j%Ten]=1; -J/=Ten; +     } -      for(intI=1;i<Ten; i++) +num[0]+=Num[i]; A     if(num[0]==Ten) at     { -printf"%d/%05d =%d\n", fenzi,fenmu,n); -ok=true; -     } - } - intMain () in { -     intflag=0; to      while(~SCANF ("%d",&N)) +     { -         if(n==0) Break; the         if(flag) printf ("\ n"); *flag=1; $ Panax Notoginsengok=false; -          for(intI=1234;i<50000; i++) the         { +memset (NUM,0,sizeof(num)); A             intj=i*N; the             if(j>=100000)Continue; + solve (i,j); -         } $         if(!ok) printf ("There is no solutions for%d.\n", n); $     } -     return 0; -}

UVA 725 Division

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.