zoukankan      html  css  js  c++  java
  • UVa1586,Molar Mass

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    int main()
    {
     double c,h,o,n;
     int t,i,j;
     cin>>t;
     getchar();
     double ans;
     char s[100];
     while (t-->0)
     {
      gets(s);
      c=0;
      h=0;
      o=0;
      n=0;
         int len=strlen(s);
      i=0;
      j=0;
      while(i<len){ 
       if (s[i]>='A'&&s[i]<='Z'){
        if (s[i+1]>='0'&&s[i+1]<='9')
        {
         j=j*10+s[i+1]-'0';
         if (s[i+2]>='0'&&s[i+2]<='9') j=j*10+s[i+2]-'0';
        } else j=1;
        if(s[i]=='C') c+=j;
        if(s[i]=='H') h+=j; 
        if(s[i]=='O') o+=j;
        if(s[i]=='N') n+=j;
        j=0;
       }
       i++;
      }
      printf("%.3lf\n",c*12.01+h*1.008+o*16.00+n*14.01);
     }
    }

  • 相关阅读:
    第二周作业
    第一次作业
    第0次作业
    第一次的作业
    第0次作业
    第三次作业
    %f使用时的注意事项
    关于c++停止工作
    第二次作业
    第一次作业
  • 原文地址:https://www.cnblogs.com/acbingo/p/3869158.html
Copyright © 2011-2022 走看看