POJ 1426 Find The Multiple

来源:互联网 发布:三国志9优化伴侣版本 编辑:程序博客网 时间:2024/05/16 06:02
/*algorithm: BFS*/#include <iostream>#include <queue>using namespace std;int n;void BFS(){queue<__int64> q;q.push(1);while (!q.empty()) {if (q.front() % n == 0) {cout << q.front() << endl;return;}__int64 head = q.front();q.pop();q.push(head * 10);q.push(head * 10 + 1);}}int main(){while (cin >> n && n != 0) {BFS();}return 0;}

0 0
原创粉丝点击