-
Notifications
You must be signed in to change notification settings - Fork 1
/
10424 Love Calculator-ha5Zt8SF.txt
63 lines (63 loc) · 1.51 KB
/
10424 Love Calculator-ha5Zt8SF.txt
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
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cctype>
#include<cstdlib>
using namespace std;
int process(int a)
{
int sum;
while(a>9){
int temp=a;
sum=0;
while(temp!=0){
sum+=(temp%10);
temp/=10;
}
a=sum;
}
return a;
}
int main()
{
char name1[25],name2[25];
int len1,len2,sum1,sum2;
while(gets(name1)&&gets(name2)){
len1 = strlen(name1);
len2 = strlen(name2);
sum1=0,sum2=0;
int i;
for( i=0; i<len1; i++){
if(isalpha(name1[i])){
if(isupper(name1[i]))
sum1+=(name1[i]-64);
else
sum1+=(name1[i]-96);
}
}
for( i=0; i<len2; i++){
if(isalpha(name2[i])){
if(isupper(name2[i]))
sum2+=(name2[i]-64);
else
sum2+=(name2[i]-96);
}
}
//cout<<sum1<<" "<<sum2<<endl;
sum1=process(sum1);sum2=process(sum2);
float percent;
if(sum1==sum2)
percent=1;
else
percent = sum1>sum2 ? (float)sum2/(float)sum1 : (float)sum1/(float)sum2;
if(sum1==0 && sum2==0)
printf("\n");
else if(sum1==0 || sum2==0){
percent=0;
printf("%.2f %\n",percent*100);
}
else
printf("%.2f %\n",percent*100);
}
return 0;
}