-
Notifications
You must be signed in to change notification settings - Fork 0
/
01586.cpp
36 lines (32 loc) · 990 Bytes
/
01586.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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
cout << fixed << setprecision(3);
ll t; cin >> t;
while(t--){
unordered_map<char, ll> chemic;
string str; cin >> str;
for(ll i = 0; i < str.length(); i++){
char catc = str[i];
if(i < str.length()-1 && isdigit(str[i+1])){
string angka = "";
++i;
while(i < str.length() && isdigit(str[i])){
angka += str[i];
++i;
}
--i;
chemic[catc] += stoi(angka);
}
else ++chemic[catc];
}
double res = chemic['C']*12.01 + chemic['H']*1.008 + chemic['O']*16.00 + chemic['N']*14.01;
cout << res << "\n";
}
return 0;
}