-
Notifications
You must be signed in to change notification settings - Fork 0
/
10424.cpp
65 lines (54 loc) · 823 Bytes
/
10424.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<stdio.h>
#include<ctype.h>
#include<string.h>
/* Love Calculator - 10424 */
int sum(int love){
int i,j,aux1,aux2,ant,vet[5];
i=0; aux1=10; aux2=1; ant=0;
while(love/aux2>0)
{
vet[i]=(love%aux1-ant)/aux2;
ant=love%aux1;
aux1*=10;
aux2*=10;
i++;
}
love=0;
for(j=0;j<=i-1;j++)
love+=vet[j];
return love;
}
int love(char* name,int size){
int i,love=0;
for(i=0;i<size;i++)
{
if(islower(name[i]))
love+=name[i]-96;
else
if(isupper(name[i]))
love+=name[i]-64;
}
while(love>9)
love=sum(love);
return love;
}
main(){
int i,sh,sm;
float lh,lm,ratio;
char h[26],m[26];
while(1)
{
if(gets(h)==NULL)
break;
gets(m);
sh=strlen(h);
sm=strlen(m);
lh=love(h,sh);
lm=love(m,sm);
if(lh<lm)
ratio=lh/lm*100;
else
ratio=lm/lh*100;
printf("%.2f %%\n",ratio);
}
}