1426:Find The Multiple BFS

题目连接

没读透题,,以为是答案最长200位,所以用string写的,,写了会没写出来,看了题解才知道,也是一个简单题。

#include <iostream>
#include <queue>
using namespace std;
int main()
{
    
    
    int N;
    while (cin >> N)
    {
    
    
        if (!N)
            break;
        queue<long long> q;
        q.push(0);
        while (!q.empty())
        {
    
    
            long long x = q.front();
            q.pop();
            if (x != 0 && x % N == 0) // 排除一开始是0的情况
            {
    
    
                cout << x << endl;
                break;
            }

            if (x != 0) // 避免一直是0
                q.push(x * 10 + 0);
            q.push(x * 10 + 1);
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_45653525/article/details/113066947
今日推荐