基本思想:
从第一个数入手,可以简单的限定范围,100~333,否则不满足三位数提议;
开始枚举,利用数组来进行数位标记;
关键点:
无;
#include<iostream> #include<stdlib.h> #include<stdio.h> #include<vector> #include<string> #include<math.h> #include<algorithm> #include<cstring> using namespace std; typedef long long ll; bool charge[10]; bool chargement(int n) { while (n!=0){ if (charge[n % 10]) { return false; //代表重复 } charge[n % 10] = true; n /= 10; } //无重复 return true; } bool func(int a, int b, int c) { fill(charge, charge + 10, false); charge[0] = true; if (!chargement(a) || !chargement(b) || !chargement(c)) return false; return true; } int main(){ fill(charge, charge + 10, false); for (int i = 100; i < 333; i++) { int a = i * 2; int b = i * 3; if (func(i,a,b)) { cout << i << " " << a <<" "<< b << endl; } } return 0; }