Skip to content

Commit ba7359c

Browse files
committed
202 cpp solution
1 parent 1b9bbcf commit ba7359c

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Author: illuz <iilluzen[at]gmail.com>
3+
* File: AC_simulation_n.cpp
4+
* Create Date: 2015-04-22 17:29:42
5+
* Descripton:
6+
*/
7+
8+
#include <bits/stdc++.h>
9+
10+
using namespace std;
11+
const int N = 0;
12+
13+
class Solution {
14+
public:
15+
bool isHappy(int n) {
16+
unordered_set<int> vis;
17+
18+
while (vis.find(n) == vis.end()) {
19+
vis.insert(n);
20+
int tmp = 0;
21+
while (n) {
22+
tmp += (n%10) * (n%10);
23+
n /= 10;
24+
}
25+
n = tmp;
26+
if (n == 1)
27+
return true;
28+
}
29+
30+
return false;
31+
}
32+
};
33+
34+
int main() {
35+
Solution s;
36+
int n;
37+
for (n = 0; n < 10000; ++n) {
38+
if (s.isHappy(n))
39+
cout << n << ", ";
40+
}
41+
return 0;
42+
}
43+

0 commit comments

Comments
 (0)