例题9.2Find The Multip
#include<iostream>
#include<queue>
using namespace std;
void BFS(int n)
{
queue<long long> q;
q.push(1);
while(!q.empty())
{
long long current=q.front();
q.pop();
if(current%n==0)
{
cout<<current<<endl;
break;
}
else
{
q.push(current*10);
q.push(current*10+1);
}
}
}
int main()
{
int n;
while(cin>>n)
{
if(n==0)break;
BFS(n);
}
}
#include<queue>
using namespace std;
void BFS(int n)
{
queue<long long> q;
q.push(1);
while(!q.empty())
{
long long current=q.front();
q.pop();
if(current%n==0)
{
cout<<current<<endl;
break;
}
else
{
q.push(current*10);
q.push(current*10+1);
}
}
}
int main()
{
int n;
while(cin>>n)
{
if(n==0)break;
BFS(n);
}
}
全部评论
相关推荐
点赞 评论 收藏
分享

点赞 评论 收藏
分享
05-29 09:02
门头沟学院 Java 点赞 评论 收藏
分享