문제접근![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==)
•
v벡터에 d(n)의 결과값을 모두 저장
•
10000까지 돌면서 v벡터에 없으면 셀프넘버
놓쳤던 부분![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==)
코드![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==)
2160 KB
12 ms
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void)
{
vector<int> v;
int i = 0;
int n;
int tmp;
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
while (++i <= 10000)
{
n = i;
tmp = n;
while (n >= 10)
{
tmp += n % 10;
n /= 10;
}
tmp += n;
v.push_back(tmp);
}
sort(v.begin(), v.end());
i = 0;
while (++i <= 10000)
{
if (find(v.begin(), v.end(), i) != v.end())
continue ;
else
cout << i << "\n";
}
return (0);
}
C++
복사