-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuva-10591.cpp
More file actions
39 lines (30 loc) · 840 Bytes
/
uva-10591.cpp
File metadata and controls
39 lines (30 loc) · 840 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
#include <bits/stdc++.h>
using namespace std;
int main()
{
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
char numStr[20];
int test, t, sum, Len, i;
scanf("%d", &test);
for (t = 1; t <= test; t++) {
scanf("%s", numStr);
printf("Case #%d: %s is ", t, numStr);
Len = strlen(numStr);
do {
sum = 0;
for (i = 0; i < Len; i++) {
sum += (numStr[i] - '0') * (numStr[i] - '0');
}
sprintf(numStr, "%d", sum);
Len = strlen(numStr);
} while (Len != 1);
if (numStr[0] == '1' || numStr[0] == '7') {
printf("a Happy number.\n");
}
else {
printf("an Unhappy number.\n");
}
}
return 0;
}