[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 }