解题思路:
经过简单分析,就能知道第一个数只可能是四位数,因为从小到大输出的原因,第二个数只可能是个位数或者两位数,第三个数不用遍历直接相除得到,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 人评分
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)浏览:546 |
【回文数(二)】 (C语言代码)浏览:856 |
字符串对比 (C语言代码)浏览:1413 |
C语言训练-大、小写问题 (C语言代码)浏览:732 |
WU-蓝桥杯算法提高VIP-Quadratic Equation (C++代码)浏览:1752 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:517 |
循环入门练习6 (C语言代码)浏览:970 |
罗列完美数 (C语言代码)浏览:491 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:706 |
C语言程序设计教程(第三版)课后习题6.8 (C语言代码)浏览:617 |