#include#include #include using namespace std;int main(){ int N; cin>>N; while(N--) { double numC=0,numH=0,numN=0,numO=0; string s; cin>>s; int len = s.length(); for(int i=0;i ='1'&&s[i]<='9'){ int tmp,flag=0; if(s[i+1]>='1'&&s[i+1]<='9'){ tmp = (s[i]-'0')*10+s[i+1]-'0'-1; flag=1; } else tmp=s[i]-'0'-1; if(s[i-1]=='C')numC+=tmp; if(s[i-1]=='H')numH+=tmp; if(s[i-1]=='O')numO+=tmp; if(s[i-1]=='N')numN+=tmp; if(flag==1)i++; } } double sum = numC*12.01+numH*1.008+numN*14.01+numO*16.00; cout< < < <
这个题目我能想到的就是这些啦,思路还是挺简单的,写的程序可能有点繁琐。