H - Molar mass

#include <bits/stdc++.h>
using namespace std;



int main(){ 
	int n;
	double weight[300];
	weight['C']=12.01;
	weight['H']= 1.008;
	weight['O']= 16;
	weight['N']=14.01;
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		double sum=0,count=0,price=0;
		for(int j=0;j<s.size();j++){
			char cc[20]={'\0'};
			int t=0;
			price = weight[s[j++]];
			while(s[j]>='0'&&s[j]<='9')
			cc[t++]=s[j++];
			j--;
			if(t>0)count = atof(cc);
			else count=1;
			sum+=count*price;
		}
		printf("%.3lf\n",sum);
	} 
	return 0;
}

 

相关文章:

  • 2022-12-23
  • 2021-06-21
  • 2022-01-31
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
猜你喜欢
  • 2022-12-23
  • 2021-10-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案