分子量 Molar Mass
#include<iostream>
#include<stack>
#include<cmath>
#include<map>
#include<cstdio>
using namespace std;
int main()
{
map<char,float> v;
v['C']=12.01;
v['H']=1.008;
v['O']=16.00;
v['N']=14.01;
stack<char> s;
int n;
scanf("%d",&n);
getchar();
for(int i=0;i<n;i++)
{
float sum=0.0;
char a;
int c=0;
while((a=getchar())!='\n')
{
s.push(a);
}
char e;
int count=0;
while(!s.empty())
{
e=s.top();
s.pop();
if(isalpha(e)&&c==0)
{
sum+=v[e];
}
else if(isdigit(e))
{
int k1=e-'0';
c=c+k1*pow(10,count);
count++;
}
else if(isalpha(e))
{
sum+=c*v[e];
count=0;
c=0;
}
}
printf("%.3f\n",sum);
}
return 0;
}