#include<iostream>
#include<string>
#include<string.h>
#include<cmath>
#include <iomanip>
using namespace std;
int main()
{
int n;
cin>>n;
string s;
while(n--)
{
cin>>s;
int len=s.length();
int a[4];
//CHON
a[0]=0;
a[1]=0;
a[2]=0;
a[3]=0;
float sum=0;
for(int i=0;i<len;i++)
{
if(i+1==len){
if(s[i]=='C')
a[0]++;
if(s[i]=='H')
a[1]++;
if(s[i]=='O')
a[2]++;
if(s[i]=='N')
a[3]++;
}
else
{
if(s[i]=='C'&& (s[i+1]=='H'||s[i+1]=='C'||s[i+1]=='O'||s[i+1]=='N'))
a[0]++;
if(s[i]=='H' &&(s[i+1]=='C'||s[i+1]=='H'||s[i+1]=='O'||s[i+1]=='N'))
a[1]++;
if(s[i]=='O'&&(s[i+1]=='C'||s[i+1]=='H'||s[i+1]=='O'||s[i+1]=='N'))
a[2]++;
if(s[i]=='N'&&(s[i+1]=='C'||s[i+1]=='H'||s[i+1]=='O'||s[i+1]=='N'))
a[3]++;
}
if(s[i]<='9'&&s[i]>='0'){
int t=i+1;
while(s[t]<='9'&&s[t]>='0')
{
t++;
}
int m=t-i;//e.g C12 i=1 t=3 m=2
t=i;
if(s[t-1]=='C'&&t-1>=0)
for(int j=m;j>0;j--)
{
a[0]+=(s[t]-'0')*pow(10,j-1);
t++;
}
if(s[t-1]=='H'&&i-1>=0)
for(int j=m;j>0;j--)
{
a[1]+=(s[t]-'0')*pow(10,j-1);
t++;
}
if(s[t-1]=='O'&&i-1>=0)
for(int j=m;j>0;j--)
{
a[2]+=(s[t]-'0')*pow(10,j-1);
t++;
}
if(s[t-1]=='N'&&i-1>=0)
for(int j=m;j>0;j--)
{
a[3]+=(s[t]-'0')*pow(10,j-1);
t++;
}
}
}
sum=a[0]*12.01+a[1]*1.008+a[2]*16.0+a[3]*14.01;
cout.setf(ios::fixed);
cout<<fixed<< setprecision(3) << sum <<endl;
}
return 0;
}
UVA1586
最新推荐文章于 2022-12-26 00:23:51 发布