0711编程之美找符合条件的整数

2017-07-11 19:39:19来源:CSDN作者:tiandaoxiaowu人点击

#include<iostream>#include<queue>using namespace std;int x(int n,int m){    int temp = n*m;    while (temp)    {        if (temp % 10 >= 2)            return 0;        temp=temp/10;    }    return 1;}int main711()//解法1{    int n;    while (cin >> n)    {        int m;        for (m = 1; m++;)            if (x(n, m))            {            cout << n << "," << m*n << endl;            break;            }    }    return 0;}int main()//利用深度优先搜索 解法2{    int n;    while (cin >> n)    {        queue<int>a;        a.push(1);        while (!a.empty())        {            int temp = a.front();            a.pop();            if (temp%n == 0)            {                cout << n << "," << temp << endl;                break;            }            a.push(temp * 10);            a.push(temp * 10+1);        }    }    return 0;}

微信扫一扫

第七城市微信公众平台