Find the multiple-------搜索BFS

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
void bfs(int n)
{
    queue<long long>q;
    while(!q.empty())
    {
      q.pop(); 
    }
    q.push(1);
    while(!q.empty())
    {
        long long current =q.front();
        q.pop();
        if(current%n==0)
        {
            cout<<current<<endl;
            return;
        }    
        q.push(current*10);
        q.push(current*10+1);    
    }
 }
int main()
{
 int n;
 while(cin>>n)
 {
     if(n==0)
      break;

     bfs(n);
 }
 return 0;
} 

 

posted @ 2020-09-07 15:16  Tomorrow1126  阅读(87)  评论(0编辑  收藏  举报