-
Notifications
You must be signed in to change notification settings - Fork 0
/
uva10424.cpp
60 lines (43 loc) · 1.07 KB
/
uva10424.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
#include <iostream>
#include <iomanip>
using namespace std;
int charToInt(char a){
if(a >= 97){
return a - 96;
}
return a - 64;
}
bool isAlpha(char a){
return (a >= 97 && a <= 122) || (a >= 65 && a <= 90);
}
int nameToNumber(string name){
int result(0);
for(int i = 0; i < name.size(); i++){
if(isAlpha(name[i])){
result += charToInt(name[i]);
}
}
string res = to_string(result);
while(result >= 10){
result = 0;
for(int i = 0; i < res.size(); i++){
result += res[i] - '0';
}
res = to_string(result);
}
return result;
}
int main(){
/*cout<<(0 + 'a')<<endl; // 97
cout<<(0 + 'A')<<endl; //65
cout<<(0 + 'Z')<<endl; // 90
cout<<(0 + 'z')<<endl; // 122*/
cout<<setprecision(2)<<fixed;
string l, m;
while(getline(cin>>ws, l) && ! cin.eof()){
getline(cin>>ws, m);
float r(nameToNumber(l)), s(nameToNumber(m));
cout<<(min(r, s) * 100.0) / max(r, s)<<" "<<"%"<<endl;
}
}
// medium 8 solved in 32min and 52sec