[Brute force] Divison ultraviolet A 725 (Division for getting started with brute force) and divisonultraviolet

Source: Internet
Author: User

[Brute force] Divison ultraviolet A 725 (Division for getting started with brute force) and divisonultraviolet

Question: give you a number (n), ranging from 0 ~ 9, 10 digits form two five-digit numbers, so that their quotient is n and all results are output in order.

Analysis: violence. Enumerate the second number in the range of (,), and then judge.

(According to Liu rujia zipi)

 1 #include<bits/stdc++.h> 2 using namespace std; 3 int judge(int a,int b) 4 { 5     int used[11]; 6     memset(used,0,sizeof(used)); 7     if(b>100000) return 0; 8     used[0]=1; 9     while(a)10     {11         used[a%10]=1;12         a/=10;13     }14     while(b)15     {16         used[b%10]=1;17         b/=10;18     }19     int sum=0;20     for(int i=0;i<10;i++)21         sum+=used[i];22     return (sum==10);23 }24 int main()25 {26     int n;27     while(cin>>n)28     {29         int i,flag;30         flag=0;31         for(i=1234;i<100000;i++)32         {33             if(judge(i,i*n))34             {35                 flag=1;36                 cout<<i*n<<"/"<<i<<"="<<n<<endl;37             }38         }39         if(flag==0)40         {41             cout<<"no"<<endl;42         }43     }44     return 0;45 }

 

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.