Molar mass UVA - 1586

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

const int maxn = 105;

char s[105];

int main(){
    int t;
    cin>>t;
    while(t--){
       scanf("%s",s);
    double M,sum=0.0;
    int len=strlen(s);
    for(int i=0;i='0'&&s[i]<='9')continue;
        if(s[i]=='C')
            M=12.01;
        else if(s[i]=='H')M=1.008;
        else if(s[i]=='O')M=16.00;
        else if(s[i]=='N')M=14.01;
        int p=i+1;
        int n;
        if(s[p]>='0'&&s[p]<='9'){
            n=0;
            while(s[p]>='0'&&s[p]<='9'){
                n=n*10+s[p]-'0';
                p++;
            }
        }
        else
            n=1;

            sum+=M*n;
    }
    printf("%.3lf\n",sum);
    }
    return 0;
}

你可能感兴趣的:(紫书)