-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermutation3.cpp
54 lines (40 loc) · 885 Bytes
/
permutation3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <cstdio>
#include <algorithm>
#include <set>
using std::sort;
int nums[9], t = 0;
bool pushNumber(int x)
{
while (x != 0)
{
nums[t] = x % 10;
if (x % 10 == 0) return false;
x /= 10;
++t;
}
return true;
}
bool isVaild(int& abc, int& def, int& ghi)
{
if (def < 100 || def > 999) return false;
if (ghi < 100 || ghi > 999) return false;
t = 0;
if (!pushNumber(abc)) return false;
if (!pushNumber(def)) return false;
if (!pushNumber(ghi)) return false;
sort(nums, nums + 9);
for (int i = 8; i > 0; i--)
if (nums[i - 1] == nums[i]) return 0;
return true;
}
int main()
{
int abc = 100, def, ghi;
for (; abc <= 999; abc++)
{
def = 2 * abc;
ghi = 3 * abc;
if (isVaild(abc, def, ghi)) printf("%d %d %d\n", abc, def, ghi);
}
return 0;
}