BeakJoon
백준 4673 : 셀프 넘버
연결리스트
2020. 8. 28. 00:12
소스코드
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
|
#include <iostream>
using namespace std;
void self() {
int sum[10000] = { 0 };
int res = 0;
for (int i = 1; i < 10000; i++) {
if (i >= 10 && i < 100) {
res = i + i % 100 / 10 + i % 10;
sum[res] = 1;
}
else if (i < 1000) {
res = i + i / 100 + i % 100 / 10 + i % 10;
sum[res] = 1;
}
else if (i < 10000) {
res = i + i / 1000 + i % 1000 / 100 + i % 100 / 10 + i % 10;
if (res < 10000) {
sum[res] = 1;
}
}
else if(i < 10){
res = i + i;
sum[res] = 1;
}
}
for (int i = 1; i < 10000; i++) {
if (sum[i] != 1) {
cout << i << endl;
}
}
}
int main() {
self();
return 0;
}
|
cs |