forked from Diusrex/UVA-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
10424 Love Calculator.cpp
49 lines (40 loc) · 943 Bytes
/
10424 Love Calculator.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
#include <cstdio>
int Calculate(char *name)
{
int total(0), temp;
while (*name)
{
if (*name >= 'a' && *name <= 'z')
// Starts at 1, so used value 1 before 'a'
total += *name - 96;
else if (*name >= 'A' && *name <= 'Z')
total += *name - 64;
++name;
}
while (total >= 10)
{
temp = 0;
while (total)
{
temp += total % 10;
total /= 10;
}
total = temp;
}
return total;
}
int main()
{
char nameOne[30], nameTwo[30];
int first, second;
while (gets(nameOne))
{
gets(nameTwo);
first = Calculate(nameOne);
second = Calculate(nameTwo);
if (first < second)
printf("%.2f %%\n", first * 100.0 / second);
else
printf("%.2f %%\n", second * 100.0 / first);
}
}