-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy path10591.cpp
executable file
·50 lines (46 loc) · 1.01 KB
/
10591.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
/* Problem: Happy Number UVa 10591
Programmer: Md. Mahmud Ahsan
Description: Ad hoc, if any repetion of the new number then unhappy
Compiled: Visual C++ 7.0
Date: 03-06-05
*/
#include <iostream>
using namespace std;
long array[10000];
int main(){
long item, itemOrg, j, store;
int cases = 0, test, t, k, temp, flag;
cin >> test;
for (t = 0; t < test; ++t){
cin >> item;
itemOrg = item;
flag = 100; // flag but 1,0 both is needed
k = 0;
while (flag != 1 && flag != 0){
store = 0;
while (item != 0){
temp = item % 10;
item = item / 10;
store += temp * temp;
}
item = store;
if (store == 1)
flag = 1;
else{
array[++k] = store;
for (j = k-1; j > 0; --j){
if (store == array[j]){
flag = 0;
break;
}
}
}
}
cout << "Case #" << ++cases << ": ";
if (flag)
cout << itemOrg << " is a Happy number." << endl;
else
cout << itemOrg << " is an Unhappy number." << endl;
}
return 0;
}