zoukankan      html  css  js  c++  java
  • UVA-1586 Molar mass

     1 #include <iostream>
     2 #include <stdlib.h>
     3 #include <string>
     4 #include <vector>
     5 #include <algorithm>
     6 #include <string.h>
     7 #include <stack>
     8 #include <unordered_map>
     9 #include <math.h>
    10 #include <iomanip>
    11 
    12 using namespace std;
    13 
    14 vector<double> molar2MassList {12.01,1.008,16.00,14.01};
    15 enum molarList {C,H,O,N};
    16 
    17 int main()
    18 {
    19     int T;
    20     cin >> T;
    21     while(T --)
    22     {
    23         string input;
    24         cin >> input;
    25         double result = 0;
    26         for(int i = 0; i < input.size(); i ++)
    27         {
    28             enum molarList state;
    29             double num = 0;
    30             int digit = 0;
    31             if(input[i]=='C')
    32             {
    33                 state = C;
    34                 result += molar2MassList[state];
    35             }
    36             else if(input[i]=='H')
    37             {
    38                 state = H;
    39                 result += molar2MassList[state];
    40             }
    41             else if(input[i]=='O')
    42             {
    43                 state = O;
    44                 result += molar2MassList[state];
    45             }
    46             else if(input[i]=='N')
    47             {
    48                 state = N;
    49                 result += molar2MassList[state];
    50             }
    51             else
    52             {
    53                 while(isdigit(input[i]))
    54                 {
    55                     num = pow(10,digit++) * num + (input[i++]-'0');
    56                 }
    57                 result += (num-1)*molar2MassList[state];
    58                 i --;
    59             }
    60         }
    61         cout << fixed << setprecision(3) << result << endl;
    62     }
    63     return 0;
    64 }
  • 相关阅读:
    编程语言
    MySQL之常用函数
    Java常用工具类
    数据结构
    Java对接SAP平台接口
    Maven项目依赖管理工具
    Java设计模式--抽象工厂
    Java基础--抽象类与接口
    Java集合--ArrayList遍历删除元素
    Java注解(Annotation )--结合拦截器实现是否登录验证
  • 原文地址:https://www.cnblogs.com/Asurudo/p/9597323.html
Copyright © 2011-2022 走看看