forked from illuz/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAC_simulation_n.cpp
More file actions
43 lines (36 loc) · 761 Bytes
/
Copy pathAC_simulation_n.cpp
File metadata and controls
43 lines (36 loc) · 761 Bytes
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
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: AC_simulation_n.cpp
* Create Date: 2015-04-22 17:29:42
* Descripton:
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
class Solution {
public:
bool isHappy(int n) {
unordered_set<int> vis;
while (vis.find(n) == vis.end()) {
vis.insert(n);
int tmp = 0;
while (n) {
tmp += (n%10) * (n%10);
n /= 10;
}
n = tmp;
if (n == 1)
return true;
}
return false;
}
};
int main() {
Solution s;
int n;
for (n = 0; n < 10000; ++n) {
if (s.isHappy(n))
cout << n << ", ";
}
return 0;
}