hh198


私信TA

用户名:hh198

访问量:1617

签 名:

等  级
排  名 1996
经  验 2415
参赛次数 1
文章发表 4
年  龄 0
在职情况 学生
学  校 山师
专  业

  自我简介:

解题思路:

经过简单分析,就能知道第一个数只可能是四位数,因为从小到大输出的原因,第二个数只可能是个位数或者两位数,第三个数不用遍历直接相除得到,a将第一个数和第二个数直接暴力枚举,然后判断是否满足每个数都只出现一次的条件,时间复杂度O(1e6)

注意事项:


注意只能出现1-9,记得把0考虑并排除
参考代码:

#include <cstdio>

#include <algorithm>

#include <iostream>

#include <cmath>

#include <cstring>

#include <stack>

#include <queue>

#include <set>

#include <map>

#include <vector>

#include <sstream>

using namespace std;

typedef long long ll;

const int inf=0x3f3f3f3f;

const ll mod=1e9+7;

const ll N=100005;

const double pai=3.14159265358979;

const ll maxn2=1e3+2;

#define mem(a,b) memset(a,b,sizeof(a))

priority_queue<int,vector

bool flag=0;

string s;

map

vector

bool vis[15];

bool check(string s)//检测是否满足条件

{

    mem(vis, false);

    if(s.size()!=9)return false;

    else

    {

        for(int i=0;i<s.size();++i)

        {

            if(vis[s[i]-'0'] || s[i] == '0')return false;//出现过或者存在0

            vis[s[i]-'0']=true;

        }

        return true;

    }

}

int main()

{

    for(int i=1000;i<10000;++i){

        for(int j=1;j<100;++j){

            if(i%j==0){

                string s="";

                int k=i/j;

                s=to_string(i)+to_string(j)+to_string(k);//int型转换为string型

                if(check(s))

                    cout << i << " = " << j << " x " << k << endl;

            }

        }

    }

    return 0;

}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区