#include<stdio.h> #include<string.h> #include<ctype.h> int main(){ int n; char s[100]; int num;//数字 scanf("%d",&n); for(int j=0;j<n;j++){ scanf("%s",s); int len=strlen(s); double t=0.0; double count=0; num=0;//初始化为0 for(int i=0;i<len;i++){ if(s[i] == ‘C‘){ t=12.01; count += t; } else if(s[i] == ‘H‘){ t=1.008; count += t; } else if(s[i] == ‘O‘){ t=16.00; count += t; } else if(s[i] == ‘N‘){ t=14.01; count += t; } else { int a; a = (s[i]-‘0‘); //判断数字有几位 if(!isdigit(s[i+1])){ num += a; count += (num-1)*t; num=0; } else num += a*10; } } printf("%.3f\n",count); } return 0; }
时间: 2024-12-08 17:14:21