1 #include <iostream> 2 #define MAXN 100 3 #define index _index 4 5 using namespace std; 6 7 bool boo; 8 int n; 9 int ans[MAXN]; 10 11 int index; 12 13 void DFS(int num,int wide); 14 15 int main() 16 { 17 // freopen("in.txt","r",stdin); 18 // freopen("out.txt","w",stdout); 19 while(cin>>n,n) 20 { 21 boo = false; 22 index = 0; 23 ans[index ++] = 1; 24 //cout<<n<<endl; 25 DFS(1,1); 26 } 27 } 28 29 void DFS(int num,int wide) 30 { 31 if(boo) 32 { 33 return; 34 } 35 if(num == 0) 36 { 37 int i; 38 for(i = 0; i < index; ++ i) 39 { 40 cout<<ans[i]; 41 } 42 cout<<endl; 43 // cout<<" ********* "<<endl; 44 boo = true; 45 return; 46 } 47 //cout<<num<<endl; 48 if(wide < 100) 49 { 50 ans[index ++] = 0; 51 DFS( (num*10)%n,wide + 1); 52 if(boo) 53 return; 54 -- index; 55 ans[index ++] = 1; 56 DFS( (num*10+1)%n,wide + 1); 57 -- index; 58 } 59 }
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。
技术网站地址: vmfor.com