uva3900

来源:互联网 发布:淘宝配色怎么改 编辑:程序博客网 时间:2024/06/05 02:05

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
    int T;
    scanf("%d",&T);
    char s[82];
    while(T--){
        scanf("%s",s);
        int n=strlen(s);
        s[n]='p';
        n++;
        s[n]='/0'; 
        char *f,*l;
        f=l=s;
        l++;
        int C=0,O=0,H=0,N=0,x=0;
        while(*l!='/0'){
             //
            if(*f=='C'&&*l>='0'&&*l<='9'){
                 x=0;
                f+=2;
                x=x*10+(*l-'0');
                 l++;
                 if(*l>='0'&&*l<='9'){
                    x=x*10+(*l-'0');f++;l++;}
                 l++;
                 //cout<<x<<endl;
                 C=C+x;}
                
             else if(*f=='C'&&(*l<'0'||*l>'9')){
                  C++;f++;l++;}
                 
              //   
              else if(*f=='O'&&*l>='0'&&*l<='9'){
                  x=0;
              f+=2;
              x=x*10+(*l-'0');
              l++;
              if(*l>='0'&&*l<='9'){
                    x=x*10+(*l-'0');f++;l++;}
                    l++;
                 O=O+x;
              }
             
              else if(*f=='O'&&(*l<'0'||*l>'9')){
                  O++;f++;l++;}
               
               
                //   
               else if(*f=='H'&&*l>='0'&&*l<='9'){
                   x=0;
                   f+=2;
                   x=x*10+(*l-'0');
             l++;
             if(*l>='0'&&*l<='9'){
                    x=x*10+(*l-'0');f++;l++;}
                    l++;
                 H=H+x;
             }
            
              else if(*f=='H'&&(*l<'0'||*l>'9')){
                  H++;f++;l++;}
               
               
                //       
               else if(*f=='N'&&*l>='0'&&*l<='9'){
                   x=0;
              f+=2;x=x*10+(*l-'0');
              l++;
              if(*l>='0'&&*l<='9'){
                    x=x*10+(*l-'0');f++;l++;}
                    l++;
                 N=N+x;}
                
              else if(*f=='N'&&(*l<'0'||*l>'9')){
                  N++;f++;l++;}
             
              }
        double ans=0.0;//cout<<C<<" "<<H<<" "<<O<<" "<<N<<endl;
        ans=C*12.01 +H*1.008 +O*16.00 +N*14.01;
       printf("%.3lf/n",ans);
        }
       
        //system("pause");
        return 0;}

 

 

原创粉丝点击