poj1426简单BFS

#include <stdio.h>
#include
#include
#include
#include
#include
using namespace std;
int n;
queue q;
void bfs()
{
q.push(1);
while(!q.empty())
{
long long a=q.front();
q.pop();
if(a%n==0)
{
cout<<a<<endl;
return ;
}
q.push(a10);
q.push(a
10+1);
}

}
int main()
{
while(scanf("%d",&n)&&n!=0)
{
while(!q.empty())
q.pop();
bfs();
}
return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42424319/article/details/89159559