-
Notifications
You must be signed in to change notification settings - Fork 14
/
10424.cpp
48 lines (47 loc) · 2.14 KB
/
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
#include<iostream>
#include<stdio.h>
using namespace std;
long long digSum(long long n){
long long sum=0;
while(n>0){
sum+=n%10;
n/=10;
}
return sum;
}
int main(){
string strA,strB;
while(getline(cin,strA) && getline(cin,strB)){
int lenA=strA.length(), lenB=strB.length(),i;
long long sumA=0,sumB=0;
for(i=0;i<lenA;i++){
if(isalpha(strA[i])){
if(isupper(strA[i]))
sumA+=(strA[i]-'A'+1);
else
sumA+=(strA[i]-'a'+1);
}
}
while(sumA>9)
sumA=digSum(sumA);
for(i=0;i<lenB;i++){
if(isalpha(strB[i])){
if(isupper(strB[i]))
sumB+=(strB[i]-'A'+1);
else
sumB+=(strB[i]-'a'+1);
}
}
while(sumB>9)
sumB=digSum(sumB);
double ratio;
if(sumA<=sumB)
ratio=(double)sumA/(double)sumB;
else
ratio=(double)sumB/(double)sumA;
ratio*=100.00;
printf("%.2lf",ratio);
cout<<" %\n";
}
return 0;
}