UVA-1586
#include<cstdio>
#include<cstring>
#include<cctype>
int ans[512];
char s[1010];
int main()
{
int T; scanf("%d", &T);
int tmp = 0; char elem = 0;
while (T--) {
memset(ans, 0, sizeof(ans));
memset(s, 0, sizeof(ans));
scanf("%s", s);
int n = strlen(s);
for (int i = 0; i < n; ++i) {
if (isalpha(s[i])) {
elem = s[i];
if (isalpha(s[i + 1]) || s[i + 1] == '\0') tmp = 1;
else if (isdigit(s[i + 1])&& isdigit(s[i + 2])) {
tmp = (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
}
else if (isdigit(s[i + 1])) {
tmp = s[i + 1] - '0';
}
ans[elem] += tmp; tmp = 0;
}
}
double mess = ans['C'] * 12.01 + ans['H'] * 1.008 + ans['O'] * 16.00 + ans['N'] * 14.01;
printf("%.3f\n", mess);
}
return 0;
}